Moving two objects proportionally

Posted by SSL on Game Development See other posts from Game Development or by SSL
Published on 2011-11-20T04:41:49Z Indexed on 2011/11/20 10:26 UTC
Read the original article Hit count: 150

Filed under:
|
|

I'm trying to move two objects away from each other at a proportional distance, but on different scales. I'm not quite sure how to do this. Object A can go from position 0.1 to 1. Object B has no limits. If object B is decreasing, then Object A should be decreasing at rate R. Likewise, if Object B is increasing, then Object A increases at rate R. How can I tie these two Object positions together so that in an update loop, they automatically update their positions?

I tried using:

ObjA.Pos +=  0.001f * ObjB.VelocityY; //0.001f is the rate

This works but there's an error each time it runs. ObjA starts off at its max position 1 but then the next time it will stop at 0.97, 0.94, 0.91 etc.. This is due to the 0.001f rate I put in. Is there a way to control the rate, yet not end up with the rounding error?

© Game Development or respective owner

Related posts about c#

Related posts about math