Get direction angle after bounce?
Atlanten
Member, PRO Posts: 56
I have some actors moving around randomly, bouncing into each other.
Every time they bounce into each other, they change direction.
How do I get to that direction angle, so that I can have the actors pointing forward at all times?
I would imagine it could be calculated using the X and Y velocities, but that's beyond me.
Any other clever (and easy) way to do it?
Every time they bounce into each other, they change direction.
How do I get to that direction angle, so that I can have the actors pointing forward at all times?
I would imagine it could be calculated using the X and Y velocities, but that's beyond me.
Any other clever (and easy) way to do it?
Comments
Create attributes to hold an X,Y location pair, and to hold an angle:
XOrigin, YOrigin, ActorAngle
Create a rule in which: when your actor collides with another specified actor, save its location as the origin point:
Change Attribute XOrigin = self.Position.X
Change Attribute YOrigin = self.Position.Y
Set a Timer such that after .5 seconds (or whatever amount gives the actor time to move enough to its new position -- might need to experiment with this value), you calculate the angular direction of the actor by using the vectorToAngle function:
Change Attribute ActorAngle = vectorToAngle(self.Position.X-XOrigin, self.Position.Y-YOrigin)
Then, apply this angle to rotate your Actor "forward".
-end of the rule-
There may be a more elegant solution, but this is at least how I'd start out trying to solve it.
Using short timers, the result is always a little jerky or flickering though.
I also tried constraining the rotation to the VectorToAngle output, looks really cool because then the actors actually turn into position. But I'm getting a bit of jitter, probably where it crosses from zero to 360 degrees... Must experiment more...
I have this vague idea that there could be a way of using the X and Y linear velocities... You know, say
velocity.x=0 and velocity.y=100 would mean 90°
x=100 and y=100 would mean 45°
x=-100 and y=0 would mean 180° and so on.
But I don't know what such a relationship would actually look like.