【发布时间】:2018-08-04 17:09:02
【问题描述】:
铰链的hingeAngle 可以作为单个浮点数检索,但不能显式设置。我正在使用铰链模拟一扇门,并且需要能够立即将角度设置为随意打开或关闭。如何实现?
铰链是通过以下方式创建的:
const float mass = 10.0f;
BoxShape boxShape = new BoxShape(Door.CollisionShape);
Vector3 pivotA = new Vector3(-Door.CollisionShape.X, Door.CollisionShape.Y, Door.CollisionShape.Z);
door.rigidBody = physics.LocalCreateRigidBody(mass, door.getRotationMatrix() * Matrix4.CreateTranslation(position), boxShape);
door.rigidBody.ActivationState = ActivationState.DisableDeactivation;
door.rigidBody.UserObject = "Door";
var axisA = Vector3.UnitY; // pointing upwards, aka Y-axis
var hinge = new HingeConstraint(door.rigidBody, pivotA, axisA);
hinge.SetLimit(-(float)Math.PI * 0.25f, 0);
physics.World.AddConstraint(hinge);
我正在移动它:
float targetVelocity = Door.OpenSpeed;
float maxMotorImpulse = 1.0f;
door.hinge.EnableAngularMotor(true, targetVelocity, maxMotorImpulse);
在每一步 BulletPhysics 都会在 targetVelocity 的基础上增加 hingeangle。我希望直接设置此值,而不是通过施加力间接设置。
【问题讨论】:
-
你写了什么代码来解决这个问题?
-
@DanielA.White 你想看什么?
标签: c# bulletphysics