AndroidAdam
16-02-2010 22:52:47
Hi, I have a problem with my character moving through walls if he pushes against them long enough. Hoping someone here can help.
I move the character by setting the velocity when a WASD key is pressed. I use C# with Mogre and MogreNewt
This works great for moving the character, and collision does occur when he hits the wall. It's only after he is pressing against the wall for an extended amount of time that he phases through it.
[attachment=1]normalNinja.png[/attachment]
[attachment=0]phasingNinja.png[/attachment]
Here's the body definition, I use a simple box primitive.
Sorry for the rather lengthy post, any help would be appreciated.
I move the character by setting the velocity when a WASD key is pressed. I use C# with Mogre and MogreNewt
bool moving = false;
if (Game.Keyboard.IsKeyDown(MOIS.KeyCode.KC_A))
{
Vector3 dir = node.Orientation * new Vector3(-1, 0, 0);
body.Velocity = dir * 3.0f;
moving = true;
}
if (Game.Keyboard.IsKeyDown(MOIS.KeyCode.KC_D))
{
Vector3 dir = node.Orientation * new Vector3(1, 0, 0);
body.Velocity = dir * 3.0f;
moving = true;
}
if (Game.Keyboard.IsKeyDown(MOIS.KeyCode.KC_W))
{
Vector3 dir = node.Orientation * new Vector3(0, 0, -1);
body.Velocity = dir * 3.0f;
moving = true;
}
if (Game.Keyboard.IsKeyDown(MOIS.KeyCode.KC_S))
{
Vector3 dir = node.Orientation * new Vector3(0, 0, 1);
body.Velocity = dir * 3.0f;
moving = true;
}
This works great for moving the character, and collision does occur when he hits the wall. It's only after he is pressing against the wall for an extended amount of time that he phases through it.
[attachment=1]normalNinja.png[/attachment]
[attachment=0]phasingNinja.png[/attachment]
Here's the body definition, I use a simple box primitive.
Collision col = new MogreNewt.CollisionPrimitives.Box(Game.World, entity.BoundingBox.Size, 0);
body = new Body(Game.World, col);
col.Dispose();
body.SetMassMatrix(mass, Vector3.ZERO);
body.AttachNode(node);
body.SetPositionOrientation(node.Position, node.Orientation);
body.IsGravityEnabled = true;
MogreNewt.BasicJoints.UpVector uv2 = new MogreNewt.BasicJoints.UpVector(Game.World, body, Vector3.UNIT_Y);
Sorry for the rather lengthy post, any help would be appreciated.