0
\$\begingroup\$

i currently developing a game using the xna API.

now the game i am developing is 2.5d.

by 2.5d i mean the character or object can move left and right and a up and down(not just by jumping) that it would look like there is depth to the level.

try to think something like little fighter 2 where you can also walk up and down.

now i need to develop a gravity system,so far i used the idea that i draw a shadow on the ground of the level,and it follows the object or character and when the character jumps,he moves parabolic like in the real world(using very simple physics).

the gravity system detects landing if the position of it's shadow is the position of the character( or the position of the character is below the position of the shadow). is there a better way to simulate gravity in this 2.5d approach?

\$\endgroup\$
0
\$\begingroup\$

I tend to define a separate jump offset, which you then manipulate with the players + shadows position when you render.

That way you don't need to compare positions with the shadow and player position (as they could be offsetted at some other point in your game). You just check if the jump offset is <= 0 length.

When it comes to the physics themselves I'd just create a velocity that adds itself to the jump offset over time and a gravity that subtracts from the offset over time. And then do a ye olde if(jumpoffset < 0) jumpoffset = 0;

That way you get the parabolic movement, simply by setting the velocity to some value you feel fits your game. :)

\$\endgroup\$
  • \$\begingroup\$ the shadow and player can't be offsetted i designed it in a way the shadow always moves in the x like the character and it moves in the y axis if the player walk to the depth of the floor(if the player doesn't jump), but i just thought i use variable that tells me each time how much to offset the player from where it's standing i can check that if he jump and that offset becomes 0 or negative he landed. thank you. on another note i am trying to do collision detection(rectangle based) is there a way i can know from what direction the detection came? \$\endgroup\$ – omer12433 Jan 24 '14 at 11:58
  • \$\begingroup\$ I think for most cases just taking a vector from the middle point of the first rectangle to the other will be enough? That's probably not perfectly accurate though. I'm sure google has the solution for a better rectangle intersection. And shouldn't XNA have something like an intersection point or something in their intersection stuff? If they even have any. Haven't used it much. :P \$\endgroup\$ – Jonkel Jan 24 '14 at 12:20
  • \$\begingroup\$ xna have a function that gives me the rectangle that creates from the intersection that doesn't help me too much \$\endgroup\$ – omer12433 Jan 24 '14 at 12:41
  • \$\begingroup\$ I'm sure googling rectangle intersection point can help you out easily. Especially if you're not rotating the rectangles. \$\endgroup\$ – Jonkel Jan 24 '14 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.