Stopping two moving objects when a certain distance between them is reached?
TitanFury
Member Posts: 55
Hello there!
Iv'e been at this for some time and can't figure it out. I have two rectangular objects: one coming into the screen from the right side and one coming into the screen from the left side. They are at the same height, so eventually they do collide and overlap. However, i want them to stop moving once a certain distance between them is reached (the x-coordinate in this instance since they are moving horizontally). I tried using the magnitude function but to no avail. How can this be done?
All help is greatly appreciated.
Cheers.
- Andrei
Comments
Have you tried setting up two game attributes object1X and object2X.
In the two objects constrain the game attributes to the actors X position i.e.
Actor 1
Constrain Attribute: game.object1X = self.Position.X
Actor 2
Constrain Attribute: game.object2X = self.Position.X
Then have a rule on each to check the distance between the game attributes. A simple case of game.object2X - game.object1X should work. If the result is less than the distance you want them to stop then stop moving the objects.
Actor 1
If (game.object2X - game.object1X <= 100)
...Stop Movement
Actor 2
If (game.object2X - game.object1X <= 100)
...Stop Movement