Jump to content
  • Advertisement
Sign in to follow this  
Dean1988

Collision actually stopping objects problem...

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
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

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

Share this post


Link to post
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 this post


Link to post
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 :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!