modify default friction to 0; add api applyImpulse (#3972)

This commit is contained in:
Leslie Leigh
2019-03-06 15:55:04 +08:00
committed by Weiliang Wang
parent 19c390b8d9
commit 2b3a26ec7d
5 changed files with 9 additions and 2 deletions
@@ -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
View File
@@ -1,3 +1,4 @@
import CANNON from 'cannon';
import { Vec3 } from '../../../core/value-types';
export interface IWrappedCANNON<T> {
+1
View File
@@ -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);