I... need... real... jumping!

Blitz3D Forums/Blitz3D Beginners Area/I... need... real... jumping!

GIB3D(Posted 2008) [#1]
I've tried making jumping with gravity and it never turns out right.

I've tried turning gravity off when colliding but doesn't work. It's because I have so, if you have the jump key down, the gravity turns off and then the jump simulates. But if you are going against a wall, it sticks to it.

If I have the gravity going all the time then the bullets, or orbs, don't come out from the right position. For example, if I have the gravity as -1, then if you're against the ground, the velocity of the player goes to -1 and the the bullet comes out from where I told it to, but - 1.

I hope someone can help me, I just need jumping code that actually works.


Ben(t)(Posted 2008) [#2]
i have a jump that negates the gravity
so say the gravity is -1
then the jump is 1.5 and is decreases as my character moves up


Ross C(Posted 2008) [#3]
I do a linepick straight down from my character, and check the distance of the pick. If it's pretty close to the ground, i turn gravity off to a certain degree, and all's well.

In your case, you could check the collision normals, but i find linepick does a great job.


sswift(Posted 2008) [#4]
The reason you are having problems simulating gravity is becuase you're not simulating real physics.

In real physics, gravity always pulls down on you, even when jumping, and even when colliding with the floor, or a wall.

But when colliding with a floor or a wall, you are prevented from going through it by the wall or floor extering an equal, but opposite force on your body. In other words, when you are in contact with the floor, gravity pulls you down at 9.8m/s^2, but the floor pushes back up at 9.8m/s^2. The net result is no movement.

But that's for flat surfaces on the XZ plane. If the surface is angled then the normal force pushing back will also be at an angle, and so the net result will be that your ball continues moving downward, but also horizontally, along the slope of the surface. Or it might bounce off it, depending on just how elastic your objects are.

And when I say elastic what I mean is how much like a rubber ball your objects are. When a person lands on the ground a lot of energy is converted into heat, and they don't bounce much. In fact, they lose so much energy with each bounce they don't appear to bounce at all. A rubber ball on the other hand will store all that energy instead of converting it to heat and then spring back into shape and bounce like you'd expect.

Since simulating all that physics realistically is probably too much for you, then what I'd do is get the surface normal of the object which was collided with. I think Blitz returns that when you collide with something.

That normal's Y component will tell you how much the object is pointing up. It should be a number between -1 and 1. If it's 0..1 then the surface points up to some degree.

Knowing that, you can turn off gravity only when an object collides with a surface which points up. Or points up a LOT. And you can enable sliding collisions for the objects and let the character slide when they are on a steep surface.


Oh and "real" jumping isn't done by turning gravity off either. You just apply a force opposite the gravity which is greater than it, and the object moves up and the gravity eventually overcomes the upward momentum and pulls the object back down again.


GIB3D(Posted 2008) [#5]
To Ben(T) : That was one of the ways I was trying and it didn't work. Because, once I hit the floor, the velocity would just keep subtracting which makes my bullets appear even lower. And I tried turning it off once I hit the floor but that also made me stick to walls.

To Ross C and SSWIFT : Thanks for that, i'll try to see what code I can come up with.


GIB3D(Posted 2008) [#6]
Ok, I've tried to find the surface normal using

p\piv is the player's pivot and x is supposed to be what it is colliding with. But it says "Collision index out of range" so I no idea what I'm doing. :(

For c = 0 To CountCollisions(p\piv)
     For x = 0 To CollisionEntity(p\piv,c)
	CollisionNY(x,c)
     Next
Next



Stevie G(Posted 2008) [#7]
OnGround = false
For c = 1 To CountCollisions(p\piv)
  if CollisionNY( p\Piv,c) > 0
    OnGround = true
    Exit
  endif
Next


Probably best to average the normals of all the p\piv collisions and determine OnGround from the resulting y normal.

Stevie


Zethrax(Posted 2008) [#8]
In regards to some of the code above, something to bear in mind with Blitz3D is that it executes the code supplied as a parameter for the 'For' command at the start of each loop iteration. By using:-

For c = 1 To CountCollisions(p\piv)

you're actually performing the collision count during each loop iteration. It's better to cache the result to a variable and use the variable in the loop instead.

eg.

num_collisions = CountCollisions(p\piv)
For c = 1 To num_collisions


GIB3D(Posted 2008) [#9]
Edit:Sorry I forgot to put in the link.

http://rapidshare.com/files/104952282/MyEngine.rar

Here's a link to the game engine I'm working on that has all the code. The code to the jumping is in startup\ents\newentities.bb

and to get to the jumping code search for
If KeyDown(jump)


The problem I'm having this time is that even though I'm in the air, it still detects that I'm colliding with a normal and I don't know why.


GIB3D(Posted 2008) [#10]
If anyone can help me in real time on MSN, my email is

green_ice_archer@...


Ross C(Posted 2008) [#11]
I'm afraid you'll need to wait till tomorrow till i help. I got stuff to do tonight :o)


GIB3D(Posted 2008) [#12]
Ok thanks ;)


Ben(t)(Posted 2008) [#13]
green did you ever try and set limits on the gravity?
for example

if gravity#<-1 then gravity#=-1


GIB3D(Posted 2008) [#14]
Yes but that doesn't help the fact that sometimes when I land, I still can't jump.


GIB3D(Posted 2008) [#15]
Looks like I'm gonna need more help with this one...

Well at first, the gravity doesn't pull me down so I'm floating in the air. Then I jump and fall just fine. The PickedNY detects the ground the first time but then it stays at 1 forever and never changes no matter how far up I go.

Here what I got for the jumping code so far

LinePick(EntityX(p\piv),EntityY(p\piv),EntityZ(p\piv),0,-6,0)	
	
p\PickNY = PickedNY()

...Movement Code

If p\PickNY > 0.5
   p\OnGround = True
       Else
	  p\OnGround = False
EndIf
		
If p\EnableJump = 1
	If KeyDown(jump)
		p\JumpOn = True
	EndIf
			
	If p\JumpOn = True
		p\Vy = Gravity
		Gravity = Gravity - .1
				
		If Gravity < -1 And p\OnGround = 1
			p\JumpOn = False
			Gravity = 1
		EndIf
	EndIf		
EndIf


EDIT : If someone could give me some good working jumping code that works going up ramps and all that stuff, it'd make my life a LOT easier instead of spending 5 years trying to code jumping myself.


Ross C(Posted 2008) [#16]
Ok, i'll def help you tonight. I've been busy and not had enough time to sit down and really look at it. Plus i forgot :o) I'll add you to my msn in about 6 hours from the time i post here :o)


GIB3D(Posted 2008) [#17]
Alright, awesome... It's 9am for me and I go to work at 10am. I'll be off at 4pm.


Ross C(Posted 2008) [#18]
Added you to my msn. I always appear offline, so message me when you get in :o)


GIB3D(Posted 2008) [#19]
Edit : Nevermind

The message that's supposed to pop up to tell me you added me didn't pop up.


Ross C(Posted 2008) [#20]
That's cool. I'll be online when i get home from work, about 8 time :o)