I’m working on making a racing game using the physics engine. At the beginning of the scene I set the RaceCar1 object angle to “0”. I have an event that fires when I press the “i” key. It increases the value of the RaceCar1 object variable Acceleration. I have another unconditional event that applies an impulse based on the RaceCar1 object angle and the value of Acceleration. This impulse is applied at the center of the sprite. I expected the sprite to move in a straight line. I expected the angle to remain “0” but it increases without limit and the object spins wildly. Why does the sprite spin when the impulse is applied to the center of the sprite?
See attached screenshot of the impulse event.
Would a trigger once condition help? Because at the moment, what’s stopping the impulse from repeating forever?
Did you define a point named “Centre”? Otherwise, you used the wrong spelling of the word - it should be the American way (“Center”), otherwise the impulse you are applying will be at 0,0 on the sprite.
However, you could just use RaceCar1.CenterX() and RaceCar1.CenterY() instead.
What stops the impulse from repeating forever is an event that decreases the acceleration.
See the screenshot below:
Thanks for pointing that out, I did not define a point named centre. I changed the event to use RaceCar1.CenterX() and RaceCar1.CenterY() instead. The sprite still spins out of control.
Are you still applying the impulse in both directions?.If so, why?
Also, do you want to use an impulse, or do you want to apply a force? This StackOverflow post might help you decide.
Personally, I’d create a point towards the front middle of the car, and apply a force to that. I imagine the middle is less stable.