# Moving two objects proportionally

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.X +=  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?

EDIT - To clarify the scenario: The user can provide a force to Object B in a vertical motion (2D game). Gravity will bring the object back down once the user lets go of the up/down button. As the object moves up or down, I want object A to move left and right on the X axis. Maximum distance to the right can be '1', and to the left can be '0.1'. Therefore, if the user keeps holding up forever,object A will still only be at 0.1.

Object A at max 1 = Object B at position 4.5 (this is the starting position)

Object A at min 0.1 = object B at position +/- 9.9

Obejct B does take the game time into account.

-
You have to define limits for object B so that you can define your rate of movement. At what position is object B at so that object A is at its min and max position? – Tetrad Nov 20 '11 at 5:25
Is the game time being taken into consideration in ObjB.VelocityY? If the time since the last frame is in the calculation, then the rate can be set to units/sec rather than 0.001f per frame. EG: ObjA.Pos += 0.1f * ObjB.VelocityY * deltaTime; – BarakatX2 Nov 20 '11 at 9:50
What do you mean by ObjA "stops" at 0.97, 0.94, etc.? If ObjB has no limits (as you state), then you should be able to just keep moving it in a positive direction until ObjA reaches its limit of 1.0, right? – Trevor Powell Nov 20 '11 at 11:28
I've updated the question. Hopefully the information is more useful. – XSL Nov 20 '11 at 14:31
@TrevorPowell - I've added some extra information, but I found that when the user lets go and the object falls back down due to gravity, even though its position is 4.5, Object A's position keeps decreasing each time the user lets go of B. I got rid of the `0.001f` and that fixed the problem, but Object A moves too fast without that damping. – XSL Nov 20 '11 at 14:35

``````ObjA.Pos.X = 1 - 0.9 * Math.Max(0, Math.Min(1, (ObjB.Pos.Y - 4.5) / (9.9 - 4.5)))