Need help with player movement !

Blitz3D Forums/Blitz3D Programming/Need help with player movement !

JPL(Posted 2003) [#1]
Hi !

This is my second question of the day ;-)

I'm working on an fps, my world is composed of a terrain a buildings placed on it. I'm looking for a commented fps framework, or at least explanations on how to manage player collisions, walk / jump.
To avoid the player climbing the walls, I've tried with a main entity (a sphere) with another small sphere under it to represent the player's feet. If the 'feet' sphere collides with something, the player can jump, else he is still in the air and cannot jump, but I've got a lot of problems and the movement of my player is not realistic, so I really need HELP since I've passed several hours on this player walk code and cannot get it to work.

Shame on me, it must be simple, but ... please help the poor coder I am !

Thanks a lot,


Doggie(Posted 2003) [#2]
I'd think merely checking the terrainY against the players position would tell you whether or not he's in the air or on the ground. Providing that's how you're controlling where he walks. Something similar as this.


While Not KeyHit(1)
If KeyDown(200) Then
MoveEntity player,0,0,.5 
EndIf
If KeyDown(208) Then
MoveEntity player,0,0,-.5 
EndIf
If KeyDown(203) Then
TurnEntity player ,0,2,0 
EndIf
If KeyDown(205) Then
TurnEntity player ,0,-2,0 
EndIf
x#=EntityX(camera)
y#=EntityY(camera)
z#=EntityZ(camera)
x1#=EntityX(player)
y1#=EntityY(player)
z1#=EntityZ(player)
terra_y#=TerrainY(terrain1,x#,y#,z#)+5
PositionEntity camera,x#,terra_y#+15,z#
If Not EntityCollided(player,2)
PositionEntity player,x1#,terra_y#+3,z1#
End If
If Not KeyDown(200) Or KeyDown(208)
AnimateMD2 player,1,0.5,20,25 :UpdateWorld
EndIf
MouseLook(camera)
UpdateWorld
RenderWorld
Flip
Wend


Doggie


JPL(Posted 2003) [#3]
Thanks a lot, but my problem is that there's also buildings with stairs in my scene, so I cannot use terrainy...

any ideas ?


Tiggertooth(Posted 2003) [#4]
A lot of games use invisible (but solid) ramps where stairs exist in the level. Quake does this for example.

It provides a much smoother movement (no sudden jerks) and the built in collision code of Blitz handles it well if the stairs aren't too steep. Depends on what effect you're going for I guess. Turn those steps into slides as far as Blitz is concerned and it becomes trivial.


jhocking(Posted 2003) [#5]
Never mind TerrainY, a similar approach would be to simply do a raytrace (LinePick) straight down. Then use PickedY to determine how far away the surface directly under the player is every frame.


JPL(Posted 2003) [#6]
Yes, that's a good idea... let's code it :-)


Madcap13(Posted 2003) [#7]
or you could just nick the castle code from your samples
directory. .. if you brought blitz3d. *:o).
I think you can download it somewhere if you havent.
in it, it has a terraign which the player can walk on
and its got a castle which the player can walk on<but its
a bit slippery for some reason>

I wouldnt feel downhearted about failed efforts in this
area. For the most part, once you've got the running/ducking
and shooting part, you've almost completed the coding part
of your FPS.
If you dont want opening or big explosions or enemies then
you actually have completed it.
ur, yeah.. as I was saying, its an integral part to FPS.


LostCargo(Posted 2003) [#8]
I know this is an old post but im going to pull this one back out. I think this is a very important issue for FPS.

Alright, Im having the same problem JPL. I have posted about this once before and though everyone pitched in i really havent found a solition i like.

My solution was a snowman configuration similar to yours.
As below:

{H} The head
{B} The body
* The foot or contact point
(BTW the trick with using the foot/contact is to have it barely inside the body so that the outer edge of the body hits a stair and lifts the unit to the next step while the smaller footer (which is away from the wall) stays out of conact with any objects from the side such as a stair or wall. THus they can only jump when standing solidly on a step. The body works best with full sliding collisions on)

Basicly i had used code just like yours to see if the (*) has hit anything. If it is touching, then the user can jump, if not then he cant. But i added another layer of complexity.
What if the user is in a hallway and jumps and hits its head. Well, i added code for that too. Great. Now if the user hits their head they fall back down instead of continuing their jump cycle.


My problem is that i am having to keep track of if the head, body or the foot are directly up and down.

I have a function which sort of does this, but i dont like having to call a function to do effect all all of these objects, expecially since i want will eventually put htem all in a type so that they can be reused. (See my code below)
Does anyone know of a way to welding objects togeather so that they still have their own individual collisions but will move as one unit or mesh? It may save some CPU cycles.



'=============================
example code: if you want it take it. I dont like the solution on a large scale


Function PLAYER_MOVE(DIR_X,DIR_Y,DIR_Z)
If EntityCollided(ENTITY_headsphere , TYPE_ENVIRONMENT ) = 0 And DIR_Y >= 0
MoveEntity entity_bodysphere ,0, DIR_Y,0
Else
If EntityCollided(ENTITY_contactsphere , TYPE_ENVIRONMENT ) = 0 And DIR_Y < 0 Then
MoveEntity entity_bodysphere ,0, DIR_Y,0
End If
End If
MoveEntity entity_bodysphere ,DIR_X, 0 ,0
MoveEntity entity_bodysphere ,0, 0 ,DIR_Z
PositionEntity entity_headsphere , EntityX(entity_bodysphere ),EntityY(entity_bodysphere )+5 ,EntityZ(entity_bodysphere )
PositionEntity entity_hero , EntityX(entity_bodysphere ),EntityY(entity_bodysphere ) ,EntityZ(entity_bodysphere )

PositionEntity entity_camera , EntityX(entity_hero ) ,EntityY(entity_hero ) +13 ,EntityZ(entity_hero )

PositionEntity entity_contactsphere , EntityX(entity_bodysphere ),EntityY(entity_bodysphere )-3 ,EntityZ(entity_bodysphere )
End Function


LostCargo(Posted 2003) [#9]
alright cancel that. I think i found a solution using collision normals
http://www.blitzbasic.com/bbs/posts.php?topic=18696

thanks anyway. I hope this helps someoneelse.