C# 是否明确设置铰链角度?

C# 是否明确设置铰链角度?,c#,bulletphysics,C#,Bulletphysics,铰链的hingeAngle可以作为单个浮点数检索,但不能显式设置。我用铰链模拟一扇门,需要能够立即设置任意打开或关闭的角度。如何做到这一点 铰链是通过以下方式创建的: const float mass = 10.0f; BoxShape boxShape = new BoxShape(Door.CollisionShape); Vector3 pivotA = new Vector3(-Door.CollisionShape.X, Door.CollisionShape.Y, Door.Coll

铰链的
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
。我希望直接设置此值,而不是通过施加力间接设置此值。

是否尝试过setMotorTarget()函数

void btHingeConstraint::setMotorTarget
(
    btScalar    targetAngle,
    btScalar    dt 
);
在单个模拟步骤中,门是否会从打开变为关闭


如果是这样,这似乎是一件危险的事情,因为可能有东西挡住了门,通过硬设置门刚体,它可能是其他形状。

您编写了什么代码来解决这个问题?@DanielA.White您希望看到什么?我通过将MotorTargetVelocity乘以-1来打开和关闭门,并使用SetLimit()函数锁定最大和最小角度。它可以工作,但并不完美。你能推荐一个替代方案吗?