mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
modify default friction to 0; add api applyImpulse (#3972)
This commit is contained in:
committed by
Weiliang Wang
parent
19c390b8d9
commit
2b3a26ec7d
@@ -3,8 +3,8 @@ import { PhysicsMaterial } from '../../assets/physics/material';
|
||||
|
||||
export const DefaultPhysicsMaterial: PhysicsMaterial = (() => {
|
||||
const result = new PhysicsMaterial();
|
||||
result.friction = 0.3;
|
||||
result.restitution = 0.3;
|
||||
result.friction = -1;
|
||||
result.restitution = -1;
|
||||
return result;
|
||||
})();
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ export class PhysicsBasedComponent extends Component {
|
||||
|
||||
public onLoad () {
|
||||
this._refSharedBody();
|
||||
this._sharedBody!.syncPhysWithScene();
|
||||
}
|
||||
|
||||
public start () {
|
||||
|
||||
@@ -204,6 +204,10 @@ export class RigidBodyComponent extends PhysicsBasedComponent {
|
||||
this._body!.applyForce(toCannonVec3(force), toCannonVec3(position));
|
||||
}
|
||||
|
||||
public applyImpulse (impulse: Vec3) {
|
||||
this._body!.applyImpulse(toCannonVec3(impulse), toCannonVec3(new Vec3()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the collision filter of this body, remember that they are tested bitwise.
|
||||
* @param {number} group The group which this body will be put into.
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import CANNON from 'cannon';
|
||||
import { Vec3 } from '../../../core/value-types';
|
||||
|
||||
export interface IWrappedCANNON<T> {
|
||||
|
||||
@@ -48,6 +48,7 @@ export class PhysicsWorld {
|
||||
|
||||
constructor () {
|
||||
this._defaultContactMaterial = new ContactMaterial(DefaultPhysicsMaterial, DefaultPhysicsMaterial);
|
||||
this._defaultContactMaterial.friction = 0;
|
||||
|
||||
this._cannonWorld = new CANNON.World();
|
||||
setWrap<PhysicsWorld>(this._cannonWorld, this);
|
||||
|
||||
Reference in New Issue
Block a user