使用线性阻尼不受物体mass属性影响
所以我使用代码动态消减速度:
import * as cc from ‘cc’;
import { CCHELP } from ‘…/…/…/VV/base/utils/CCHELP’;
const { ccclass, property } = cc._decorator;
@ccclass(‘PlayerChess’)
export class PlayerChess extends cc.Component {
private _rigidBody: cc.RigidBodyComponent = null;
public onLoad() {
this._rigidBody = this.node.getComponent(cc.RigidBodyComponent);
}
public update(dt) {
let now_V: cc.Vec3 = cc.v3();
this._rigidBody.getLinearVelocity(now_V);
let mass:number = this._rigidBody.mass;
now_V = this.SubNow_V(now_V, dt,mass);
this._rigidBody.setLinearVelocity(now_V);
}
private SubNow_V(now_V: cc.Vec3, dt: number,mass:number): cc.Vec3 {
if(now_V.x == 0 ){
return now_V;
}
let subNumber: number = 0.98*(1-dt*mass);
now_V = cc.v3(now_V.x * subNumber, now_V.y, now_V.z * subNumber);
let vLong: number = CCHELP.GetPosLong_Vect2(now_V.x, now_V.z);
if (vLong <= 1) {
now_V = cc.v3(0, now_V.y, 0);
}
return now_V;
}
}