Reversing LinearVelocity and LinearMomentum
Posted: Sun Jan 03, 2010 5:30 pm
I have a C# Class object called "Slot" that basically contains a MaxVector3 and MinVector3. All other objects that inherit this "Slot" object are constrained to motion along a line connecting these two Vector3 objects.
When a collision with one of the endpoints of the "Slot" object happens, I want to effectively reverse the linearVelocity and linearMomentum so that the item will reverse back down the Slot in the opposite direction.
I have created two C# methods to accomplish this, but neither of them is able to override the Entity.linearVelocity value (even if I set Entity.linearVelocity = Vector3.Zero). No clue why I can't override these values with their negative equivalents?
Usage Example:
When a collision with one of the endpoints of the "Slot" object happens, I want to effectively reverse the linearVelocity and linearMomentum so that the item will reverse back down the Slot in the opposite direction.
I have created two C# methods to accomplish this, but neither of them is able to override the Entity.linearVelocity value (even if I set Entity.linearVelocity = Vector3.Zero). No clue why I can't override these values with their negative equivalents?
Code: Select all
private Vector3 ReverseLinearMomentum(Vector3 currentLM)
{
Vector3 newLM = new Vector3();
if (Math.Abs(currentLM.X) > .5)
{
newLM.X = -(currentLM.X);
}
if (Math.Abs(currentLM.Y) > .5)
{
newLM.Y = -(currentLM.Y);
}
if (Math.Abs(currentLM.Z) > .5)
{
newLM.Z = -(currentLM.Z);
}
return newLM;
}
private Vector3 ReverseLinearVelocity(Vector3 currentLV)
{
Vector3 newLV = new Vector3();
if (Math.Abs(currentLV.X) > .5)
{
newLV.X = -(currentLV.X);
}
if (Math.Abs(currentLV.Y) > .5)
{
newLV.Y = -(currentLV.Y);
}
if (Math.Abs(currentLV.Z) > .5)
{
newLV.Z = -(currentLV.Z);
}
return newLV;
}
Code: Select all
Vector3 beforeV = se.DisplayModel.Entity.linearVelocity;
se.DisplayModel.Entity.linearVelocity = ReverseLinearVelocity(beforeV);