Jump to content
  • Advertisement
Sign in to follow this  
krej

Creating space like physics with box2d

This topic is 2599 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

I'm trying to create a game that takes place in space where the character can rotate freely and land on any surface at any angle he wants. So he'll be able to stand/walk on the walls and ceiling. I also want the game to have 'normal' gravity that is constantly pushing 'down' on everything else.

I'm having a little bit of trouble implementing this though. I read this article to get a general sense of how I would do it. Currently I have it so that the game finds the closest surface to you and applies a force towards the center of it. This sort of works, but I still am having some problems that I'm not sure how to fix.


As you can see in the article, they are using spheres for all of their ground-like objects. I want to use boxes though to let the player walk on a flat line, but I'm still using the same logic as the the article mentioned for spheres. So now if I have a wide box and the player tries to land on the edge of it, he will still get pulled towards the center of it instead of straight 'down' toward the part of the box he is near.

So how can I make it so that the boxes pull down relative to where the character is at, instead of towards the center? I've been trying to think of a way to get the normal of the box and I can use that as a directional vector to pull the player with, but since this all needs to happen before the player collides with the box, I'm don't know how you would do that.



EDIT: Nevermind. I was able to figure it out. What I'm doing now is taking 8 rays and shooting them off from my characters center point in every direction. Then I find which body's those rays hit, get the closest one, and apply gravity towards that one. With this raycasting method, Box2d returns the normal of the collision so I am able to easily use that as the gravity vector.

Share this post


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

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!