如下面所示,会陷进Cube里,然后松开不动就会被挤出来

用的cannon.js

刚体和碰撞和物理材质是这么设置的:


墙壁Cube碰撞什么也没改

下面是移动代码,用的刚体的setLinearVelocity
public moveWithDirection(moveDir: Vec3, dt: number): void {
if (!this._rb) return;
if (!moveDir || Vec3.equals(moveDir, Vec3.ZERO)) {
this._rb.setLinearVelocity(new Vec3(0, 0, 0));
return;
}
moveDir.normalize();
let currentVelocity = new Vec3();
this._rb.getLinearVelocity(currentVelocity);
const targetVelocity = new Vec3(moveDir.x * this.speed, currentVelocity.y, moveDir.z * this.speed);
this._rb.setLinearVelocity(targetVelocity);
this.updateRotation(moveDir, dt);
}
protected updateRotation(moveDir: Vec3, dt: number): void {
if (this._lockTarget) {
this.faceTarget(this._lockTarget, dt);
return;
}
this.faceMoveDirection(moveDir, dt);
}
protected faceMoveDirection(moveDir: Vec3, dt: number): void {
if (Vec3.equals(moveDir, Vec3.ZERO)) {
return;
}
let targetRot = new Quat();
const rot = new Vec3(moveDir.x, 0, moveDir.z).normalize();
if (rot.lengthSqr() > 0) {
targetRot = Quat.rotationTo(new Quat(), Vec3.UNIT_Z, rot);
const currentRot = this.node.getRotation();
const desiredRot = Quat.slerp(new Quat(), currentRot, targetRot, this.rotationSmoothTime * dt);
this.node.setRotation(desiredRot);
}
}
有没有大佬救一下呀,主要是参数和隔壁同事一样的,他能正常碰撞碰撞体不会陷进去,都用的设置线性速度