Collision actually stopping objects problem...

Started by
3 comments, last by rjackets 18 years, 7 months ago
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
I''m new,so take it easy.
Advertisement
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.
Okay, atm i'm not using ground i'm justy like flying around space with randomly places boxes, like you do :P

So if i read your post right,

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
I''m new,so take it easy.
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 :)
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 :)

This topic is closed to new replies.

Advertisement