# Collision actually stopping objects problem...

This topic is 4900 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Okay, so i have a theory about how to stop my box moving when i hit it, That is to record the last key pressed, then stop motion in that direction, but then if im still colliding and press left, it stops movement left, so the only way out would be back, which is a bit poo! There has to be a better way, i'm still trying to think about different ways of doing it, but i cant seem to think of a suitable one, whereas i know you guys have the experience, so any ideas guys? Cheers, Dean

##### Share on other sites
Your object should have an x/y(and z?) velocity. Hitting left/right on the keyboard should increase this velocity in the appropiate direction. Colliding with an object, in the simplest physics, would reduce the velocity to 0. The ground should have friction. For each game update, you check:
A. If the object is on the ground
B. What the current x velocity is (positive or negative)
Then reduce that velocity by a certain amount. If the velocity is near 0 (this is relative) make it 0, or your object will "vibrate".

This is a movement system in its simplest form, and I'd highly recommend it over your current one. I used your current system when I first started making games years ago, before I even knew what object oriented programming was, and its uses are very limited and frustrating.

##### Share on other sites
Okay, atm i'm not using ground i'm justy like flying around space with randomly places boxes, like you do :P

Until Up/Down is pressed Z's variable is 0, then when i press Z is jumps to Z, and i Translate the object by Z?

I've got it working in my head, just getting it into code isnt the same matter, hehe

Cheers

Dean

##### Share on other sites
Each game update (frame) you translate Z/X/Y based on their velocity. It doesn't matter when you press up/down, up/down only changes the objects velocity, not position. The position is then changed based on the object's velocity at each game update. I assume you know to use time-based movement :)

##### Share on other sites
If you have any physics background (high-school?) then it is best to think about this sort of thing as it would happen in the real world. It really does make things simpler. ie. Think of collisions in terms of impulse/mass/speed/etc and lots of good ol' vector algebra :)

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 11
• 15
• 11
• 11
• ### Forum Statistics

• Total Topics
634149
• Total Posts
3015834
×