Perfect Dead Stop
ORBZ
Member Posts: 1,304
Sometimes it's very frustrating in GS to get your actor to come to a full stop if it is controlled by physics.
It seems that this should work:
Change Velocity: 0
But it doesn't. The reason, as best I can determine, is that the physics engine carries over inertia into the next frame. So the above statement really only slows the object to a crawl.
A viable workaround that I use is this:
For 0.1s
Constrain Linear Velocity X = 0
Constrain Linear Velocity Y = 0
This results in a perfect dead stop because it forces the linear velocity X/Y to be 0 for a few frames of the physics engine, thus the inertia calculations zero out over time. Best as I can figure.
I really hope that @CodeWizard take a look at this and figure out why Change Velocity: 0 doesn't cause an object to come to a dead stop instantly. In the meantime, the above works.
It seems that this should work:
Change Velocity: 0
But it doesn't. The reason, as best I can determine, is that the physics engine carries over inertia into the next frame. So the above statement really only slows the object to a crawl.
A viable workaround that I use is this:
For 0.1s
Constrain Linear Velocity X = 0
Constrain Linear Velocity Y = 0
This results in a perfect dead stop because it forces the linear velocity X/Y to be 0 for a few frames of the physics engine, thus the inertia calculations zero out over time. Best as I can figure.
I really hope that @CodeWizard take a look at this and figure out why Change Velocity: 0 doesn't cause an object to come to a dead stop instantly. In the meantime, the above works.
Comments
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
The thing is, even if you use the linear velocity attributes to stop your actors. You MUST constrain them to 0 for at least 0.1s. If you just use Change Attribute then it only applies once and then you get a small drift.
This is particularly nasty if you move an actor off stage for recycling and it drifts out of bounds and is automatically deleted by GS.
Seems like a good suggestion, @ORBZ.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
- Thomas
Nice tip with the For 0.1s thing. >-
I posted this the other day on the very same subject:
http://forums.gamesalad.com/discussion/56981/are-these-fixestweaks-what-youd-want#latest
It seems to be more of a problem when you combine different physics behaviors. If I'm doing that I 'cancel' all of them and that seems to work out ok.
e.g in my game Yam Yam the fruit you flick has a change velocity behavior and also a constant downwards acceleration. When I pause the game (not using the pause behavior) they stop mid-air as you would expect them to.
So the value for the accelerate behavior is something like game.speed*game.pause
And game.pause is either 1 or 0
And when pause = 0
Change Linear Velocity X = 0
Change Linear Velocity Y = 0
http://www.youtube.com/watch?feature=player_embedded&v=FNQexOGvpwQ
Multiplying move behaviors by 0 also works well to stop them.
For .2sec
Constrain angular velocity to 0
Constrain linear velocity x to 0
Constrain linear velocity y to 0
Having said that I just thought you could try change max velocity to 0 if you check it and put in a high number and change it to zero I bet it stops dead in it's tracks! You can modulate the max velocity during rumtime as long as you check max velocity in the actor and access the variable through the expression editor. I remember in Puck It where I modulate max velocity that one time during testing I had max set to zero and it was at a dead stop and nothing moved it even the paddle.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS