X/Y/Z Collision

Blitz3D Forums/Blitz3D Beginners Area/X/Y/Z Collision

Sph!nx(Posted 2008) [#1]
Hi, another one from me!

I have a jump code that lets my player jump when its in collision with the world, to prevent him jumping, without his feet touching anything.

Here is the code!
If KeyHit(57) 

	If EntityCollided(player,world_col)

	 	While Player_velocityY =< 2		
		
			Player_velocityY = Player_velocityY + Gravity

		Wend
		
	EndIf
	
EndIf


It works perfect... so far. I was thinking of adding a pivot with a collision radius as a child of the player, to detect if the players feet area is touching the ground.

At this point, pressing jump and standing against the wall, makes the player fly up. Funny as it is, that's not what I need :P

Before I make the child radius, is there a way to detect if a certain part/location of a collision radius is colliding?


Thanks!!


grindalf(Posted 2008) [#2]
you could always load the walls in as a seprate entity.


Sph!nx(Posted 2008) [#3]
That is an option. I have thought of that as well.

I'd still like to know how this is done, cause I have a small team who will be working on the maps and models, so I want to do it properly so it will be as simple as possible for them.


thanks


Ross C(Posted 2008) [#4]
Check the collision normals. That will tell you what angle the collision happened.


Sph!nx(Posted 2008) [#5]
I guess your last reply in the next link is covering this. How could have I missed that thread? :-\

http://www.blitzbasic.com/Community/posts.php?topic=79122#888485


Anyway, gonna try to implement it! Thanks!


Ross C(Posted 2008) [#6]
What i do, is a linepick straight down from the characters position. Basically, it will return how close the ground is and if there is any ground below the characters. Slightly, ever so slighly slower than using normal collisions, but i find it more useful.


Stevie G(Posted 2008) [#7]
Or you could use the existing collision information to find the average collision normal in the Y direction. If it's > 0 the normal points up and your standing on something. Like so :

If KeyHit(57)

	If EntityCollided(player,world_col)
	
		If CollNY( player ) > 0

			While Player_velocityY =< 2		
				
				Player_velocityY = Player_velocityY + Gravity
		
			Wend
			
		EndIf
		
	EndIf
	
EndIf


Function CollNY#( Entity )

	Ny# = 0
	cc = CountCollisions( Entity )

	For c = 1 To cc
		Ny# = Ny# + CollisionNY( Entity , c )
	Next
	
	Return ( Ny / cc )
	
End Function		


Even then, your jumping code doesn't look right. You want to be adding an acceleration ( greater than gravity ) to the velocity in the upward direction if jump is pressed and you are on the ground. Also, apply gravity whenever you are not on the ground.

You'd need to play with the gravity and jumpacceleration variables ..

Const Gravity# = 9.81
Const JumpAcceleration# = 25.0

.
.
.
.

OnGround = ( CollNY( player ) > 0 )

If OnGround
	If KeyHit(57)
		Player_velocityY = Player_velocityY + JumpAcceleration
	EndIf
Else
	Player_velocityY = Player_velocityY - Gravity
EndIf



Stevie


Sph!nx(Posted 2008) [#8]
Thanks a lot, Stevie!