Keep Object Velocity At A Constant Speed Even After Collision?
KillerPenguinStudios
Member Posts: 1,291
Hey GS,
So I am totally having a major mind blank right now. I have an actor that is, lets say a ball.
In that actor I have a change velocity behavior.
- Its direction is set to random (0,359) - (So at the start of the scene it goes in a random direction)
- Its speed is set to 150
I place 10 of these ball actors in the scene.
I also have barriers that go around the scene to keep the balls in the scene.
Also in the ball actor I have;
- Collide with ball actor
- Collide with barrier actor
The issue I am having is the balls loose there velocity speed after so long or right after colliding. I want the ball actor to keep the speed 150 always even after it collides. It should always me moving at a constant speed of 150.
After a few hours of failed attempts I am asking for help now. I know it's probably simple, just can't think at the moment!
Thanks in advance guys!!!
Comments
Turn friction to 0 in both the ball and the barrier.
If you know the direction the ball is traveling in then you can use the following formula to kick it back into traveling at a velocity of 150:
Have you tried setting the actor's self attribute under motion, max speed to x and then check apply max speed?
Fortuna Infortuna Forti Una
Hey @Socks, I already had that done. Didn't work.
Hey @RThurman,
That is a good idea but the only issue is knowing the direction it is traveling since it is always changing when it bounces off things. Basically I just want balls bouncing around the screen at a constant speed and they can collide with one another. I couldn't figure out a way to track it's direction. My thought was if I could constantly check it's direction, create a self real attribute and constrain that self attribute to its direction. Then I could implement that into what you gave me. Not sure if that would really work or not.
Already had that. Still doing the same thing.
This is off the top of my head (untested) but it should go something like this:
Or perhaps the following might be simpler:
I just tested this and it seems the only way to keep the velocity at 150 is to constantly change the velocity if it is not 150. The method @RThurman posted works, but you also need to change it when the magnitude is above 150.
With box colliders you could keep the speed at 150 by making your actors initial direction 45, 135, 225, or 315 degrees.
Curiosity got the better of me so I spent a few minutes messing with actor physics (density, friction, bounciness, and such) to try to achieve a state where all balls kept their velocity at 150. Its pretty hard to do.
In the end, I just decided that the easiest thing to do was something line this:
I figured updating roughly 3 times a second was fast enough for human perception, but plenty slow for the device to handle.