Im using BP for the collision detection in my WP7 game. I am mapping the XZ position of 3D objects in the space to XY position of 2D sprites on screen.
Just using the basic features present in the demos I have created a 20x1x40 (xyz) cube for a base. Have made a 'maze' sitting on top of this for walls out of 1x1x1 blocks with some rooms. Then have added some spheres that can roll around through the maze (mass=1). I take the XZ coords of these spheres to map to the 2D sprites. I move the spheres by adding LinearVelosity in the direction they travel.
Most of the time this works fine but sometimes the sphere will seem to get some Y movement (there is always some small fractional part it seems) that makes it move up in the air as it travels. If I stop moving the sphere it will slowly sink down over a few seconds back to the base although gravity is set to 9.81 (as in the example). Thsi efefct can cause the sphere to move on top of other spheres or get on top of the walls etc.
My questions are:-
1. How can I fix the Y height of any object to it always stays exactly at the same height.
2. Why does it take so long to sink back down?
3. Is this some sort of interpolation thing?
4. Is there a betetr way of moving the spheres rather than just going sphere.Linearvelosity = new Vector3(x,0,z) ?
Thanks for any help!
Preventing movement in only one axis?
Re: Preventing movement in only one axis?
It appears that each frame, the velocity along the Y axis is set to 0. It can only ever accelerate for one frame before being set back to zero, so it moves down at a constant velocity of gravity * dt.2. Why does it take so long to sink back down?
Yup. Instead of setting it to (x,0,z) every frame, set it to (x, y, z), where y is a corrective velocity to return it to the desired vertical position over some time interval. y = -(ballPosition.Y - desiredY) / dt would do the trick. You could disable gravity completely and this would still work the same way.1. How can I fix the Y height of any object to it always stays exactly at the same height.
4. Is there a betetr way of moving the spheres rather than just going sphere.Linearvelosity = new Vector3(x,0,z) ?
That's probably the simplest option, but there are others (e.g. SingleEntityLinearMotors or PointOnPlaneJoints).