Completely stopping an actor in its place
msx88
Member, PRO Posts: 27
Hi!
By default, my main character is constantly scrolling but when it hits an object, I have it stop using:
if collide
linear velocity x = 0
linear velocity y = 0
For the most part it works fine. But when it hits a moving object, like a spinning projectile, every once in a while it behaves a bit erratically, like it will move into a random direction without stopping.
Would there be a surefire way to make it completely stop?
So far in the forums, I’ve found I may be able to spawn a second actor to take its place but I’m wondering if there’s another way?
Thanks in advance!
Comments
Does it start again at any point? Perhaps try using constrain attributes instead of change attributes.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
Hi Armelline, it doesn't start again after its hit. And yes, I'm using constrain attribute for the linear velocities I mentioned above. Thx.
There are many different potential approaches, and it really depends on what else is happening/needing to happen. The most reliable in situations like this is to record the X and Y position when the collision is detected, and then constrain the position to that X and Y position you recorded.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
In addition to what @Armelline mentions above I've had pretty good luck with setting the Actors Max Speed to 0 and turning on Apply Max Speed.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
What might be happening is that your actor has physics enabled and wit a spinning projectile, right after changing the velocities, the actor gets hit again by the spin and flies off. This can happen in a split second, so you wouldn't visibly see the actor stopping. In such a case, a constrain should be sufficient. You can put the constrain in a timer, for X seconds (or split seconds), just long enough to make sure the projectile either passes behind or is 100% destroyed.
But all the other solutions are good possibilities as well! It really depends on all the things happening to the actors on the scene at that moment!
Thank you so much everyone for your input, I will put all of your suggestions into consideration as I work through this!