public void ApplyRandomForce() { Vector3 pos = new NxVec3(Rand.Uniform(-4.0f, 4.0f), Rand.Uniform(-4.0f, 4.0f), Rand.Uniform(-4.0f, 4.0f)); float force = Rand.Uniform(_bodyActor.Mass * 0.5f, _bodyActor.Mass * 2.0f); _bodyActor.AddForceAtLocalPos(new Vector3(0, force * 100.0f, 0), pos); }
public void StandUp() { NxVec3 pos = _bodyActor.GlobalPosition + new Vector3(0, 2, 0); Matrix rot = _bodyActor.GlobalOrientation; NxVec3 front = Vector3.TransformNormal(new NxVec3(1, 0, 0), rot); front.Y = 0; front.Normalize(); float dotproduct = front.X; float angle = Math.Sign(-front.Z) * (float)Math.Acos(dotproduct); rot = Matrix.RotationY(angle); _bodyActor.GlobalPosition = pos; _bodyActor.GlobalOrientation = rot; _bodyActor.LinearVelocity = new NxVec3(0, 0, 0); _bodyActor.AngularVelocity = new NxVec3(0, 0, 0); }
private unsafe void _ComputeLocalVelocity() { NxVec3 relativeVelocity; _ComputeMostTouchedActor(); if (_mostTouchedActor == null || !_mostTouchedActor.IsDynamic) { relativeVelocity = _bodyActor.LinearVelocity; } else { relativeVelocity = _bodyActor.LinearVelocity - _mostTouchedActor.LinearVelocity; } _localVelocity = relativeVelocity; Matrix rotation = Matrix.Invert(_bodyActor.GlobalOrientation); Vector3.TransformNormal(ref _localVelocity, ref rotation, out _localVelocity); }