Slope Collisions

Blitz3D Forums/Blitz3D Beginners Area/Slope Collisions

kfprimm(Posted 2006) [#1]
Alright, I can setup collisions fine and everything, but whenever my character goes up a slope he slows down. Is there any way to keep him going at the same rate up a slope as if he we're of flat ground? I figure there's probably away to do it lots of math, but please, prove me wrong.


Buggy(Posted 2006) [#2]
He slows down because he's not trying to go up the slope, he's trying to go straight and the slope is pushin him up.

I'm a noob, but I think AlignToVector might help you if you align the character to the slope so that he's moving in the direction you want at the normal speed. The upside is that method doesn't involve math, but the downside is that - unless your character is an ant - it will look bad because if the character is climbing a 70 degree mountain, his body will be almost parallel to the ground!

Using math and such, I think you can use some of the collision normals functions to find the slope of the hill and head him in that direction.


kfprimm(Posted 2006) [#3]
Alright, I'll give a shot. Thanks alot.


Ross C(Posted 2006) [#4]
That's not right hehehe, surely he should go quickier up the slopes if that's the case?

Anyway, you'll need to EITHER,

Create a pivot at the players feet and apply all movements to the pivot and place the player at the pivots location every frame. This way you can use the aligntovector method on the pivot and retain the players rotations, as your only setting the position of the player to the pivots position.

OR

You can grab the collision NX NY and NZ (which ever is needed) i think it's NY though, and multiple the speed variable by this number, to adjust the speed due to the sloping.


Buggy(Posted 2006) [#5]
Thanks Ross for correcting me.


kfprimm(Posted 2006) [#6]
well, here's how I calclate my speed
x=x+Cos(yaw+90)*p\speed
z=z+Sin(yaw+90)*p\speed

i tried,
x=x+Cos(yaw+90)*(p\speed*CollisionNY(p\pivot,terraincount))
z=z+Sin(yaw+90)*(p\speed*CollisionNY(p\pivot,terraincount))

but nothing happened.


Ross C(Posted 2006) [#7]
Hmmm, you shouldn't really need to move your player like that. If you make use of the rotateentity/turnentity commands and simply use, moveentity, it will direct your entity the way it's facing. Saves you working out the maths.

CollisionNY# ( entity,index )

Parameters
entity - entity handle
index - index of collision


from the docs. is the last parameter you stated, a collision index number? You will need to count the number of collisions and use the appropriate index number.


kfprimm(Posted 2006) [#8]
Yeah, I know about MoveEntity but I don't like it much. as for CollisionNY, yes, terraincount is the index...don't know why I'm calling it that though...


Stevie G(Posted 2006) [#9]
To align the character to the slope use ...

;calculate normal of slope
Nx# = 0 : Ny# = 0 : Nz# = 0
for c = 1 to countcollisions( p\Pivot )
   Nx = Nx + collisionnx( p\Pivot , c )
   Ny = Ny + collisionny( p\Pivot , c )
   Nz = Nz + collisionnz( p\Pivot , c )
next
;align character on y-axis - does not need to be normalised
Aligntovector p\Pivot , Nx, Ny, Nz, 2, .25 

To rotate use ...
YAW = keydown(203) - keydown(205)
turnentity p\Pivot, 0, YAW, 0

To move use ....
tformvector 0,0,p\Speed, p\Pivot , 0
translateentity p\Pivot, tformedx(), tformedy(), tformedz()


Untested but this is what I use.

Stevie


kfprimm(Posted 2006) [#10]
cool, it works perfectly...except now, my character walks up walls, I'm trying different stuff to prevent that but it doesnt work.


Stevie G(Posted 2006) [#11]
How about ...


Nx# = 0 : Ny# = 0 : Nz# = 0
for c = 1 to countcollisions( p\Pivot )
   If collisionny( p\Pivot, c ) > 0
     Nx = Nx + collisionnx( p\Pivot , c )
     Ny = Ny + collisionny( p\Pivot , c )
     Nz = Nz + collisionnz( p\Pivot , c )
   next
next

Aligntovector p\Pivot , Nx, Ny, Nz, 2, .25


Basically it will only align you to poly's where the normal is pointing up the way.

Stevie


Ross C(Posted 2006) [#12]
Just do with stevie is doing. Only align if the normal is a certain angle. You might want a bit more lee-way (SP?) though.


kfprimm(Posted 2006) [#13]
alright, sweet...thanks Stevie, Ross, and Buggy.