Climbing stairs

Blitz3D Forums/Blitz3D Beginners Area/Climbing stairs

Jaydubeww(Posted 2008) [#1]
Im having trouble making my person walk up stairs...it just stops when it hits it. how can i get it to walk up stairs? Im completly stumped.


Jaydubeww(Posted 2008) [#2]
Sorry but I have another question. how to jump has been a question of mine for a long time...and I just cant seem to get it to work. please any help on what I have would be appreciated.
The code I have for jumping is this:

If KeyHit(157)
jumptime = MilliSecs()
If MilliSecs() <= jumptime + 2000

pyc = pyc + 1
EndIf

EndIf


Madcap13(Posted 2008) [#3]
I’ll try to answer both questions.

If you’re using ordinary blitzbasic collision methods, if you want a sphere<the player> to mount a box<a step>, you need to have the center of the sphere higher than the step. So, by increasing the sphere size, it can scale bigger and bigger things, katamari damacy style. However, a sphere can only mount a box if it can overcome whatever gravity you’re putting on it. So, a faster sphere would mean it scales faster. If it’s not fast enough, it won’t be able to scale at all.

Alternatively, you might be using the wrong collision method. You want one of the ones that allows sliding.

Jumping, however, is slightly more complicated.

Most thrown objects and jumping people tend to move in an arc through the air. Whether or not it’s realistic, this is how I do it.

I have a variable called something like YM#, standing for vertical momentum and Y#, which is the actual vertical coordinates for the object in question.

So, to jump, I declare YM#=50 or whatever power I want in the jump.

YM#=YM#-(millisecs()*how-slow-you-want-it-variable)

Now the part that really matters is this. Y=Y+(YM^2)
The ^2 part squares YM.

However, when YM<0 you need to do Y=Y-(YM^2) instead, as a negative number, when squared, becomes positive.

So that’s something like if YM<0 then Y=Y-(YM^2) else Y=Y+(YM^2)

Using a method like this, you’ll get a relatively sweet arc to your jumps.

Alternatively, you can just use the cos() command, start at 180 and count down to 0. Or start at 0 and count up to 180. That should give a reasonably smooth jump but it’s sort of complicated when you try to create bigger arcs as it requires faster movements and slower movement through the angles. For practicality, I don’t suggest this.


mtnhome3d(Posted 2008) [#4]
for the stairs use a transparent plane angle at the same angle as the stairs. then place it over your stairs. after that use the plane as the collision mesh.


Nate the Great(Posted 2008) [#5]
I think Madcap's way of jumping is a bit complicated, although it does work. Here's how I do it.

I have a Y# and I have YV# which stands for Y velocity.
every time it loops I say YV# = YV# - .01 for gravity.
On the next line I put Y# = Y# + YV#
These two statements combined make the player fall in a parabola.

To jump just type
If KeyDown(57) Then YV# = .1


Here is a very simple example with the added bouncing effect. :)




Ross C(Posted 2008) [#6]
Even easier. use the COS/SIN maths wave for a jump, with gravity :o) I like the bouncing though ^_^

As for climbing stairs, most games FPS wise anyway, would probably use an invisable (entityalpha 0, not hideentity) quad, or smooth mesh over the stairs.


Shambler(Posted 2008) [#7]
For stairs I like to look at which direction the player is moving in and cast a linepick slightly in front of them and straight down.

If the linepick returns a height that is within a certain limit then the player is moved upwards to this height and can then get on top of the obstacle.

This allows them to climb stairs and climb up onto things and gives a more convincing simulation of moving through the 3d world.


Nate the Great(Posted 2008) [#8]
Can someone explain what linepick does.
I just don't get it.


GIB3D(Posted 2008) [#9]
Linepick is like a beam, that starts at a position and goes out a certain length. Where ever the beam ends it checks for entities, X Y Z position, Normal X Y Z's and some other stuff.

LinePick 0,0,0,0,2,0

That means it will send a beam 2 units up.



I noticed that if you have the linepick coming out of an object as if it was parented, and you turn, something like

LinePick EntityX(object,1),EntityY(object,1),EntityZ(object,1),0,0,3

won't point the beam straight out depending on which way u are facing.
So if you turn, it will point in the same direction no matter what.


The last thing that you can put in the linepick is the beams thickness

LinePick 0,0,0,0,0,0,33


Jaydubeww(Posted 2008) [#10]
Sorry I have another question. I'm trying to keep my camera always say...6 feet above the ground, any help on this?


Nate the Great(Posted 2008) [#11]
Thanks for the explanation of line pick.


boomboom(Posted 2008) [#12]
Put this line in your camera update code at the end. Not tested.

PositionEntity camera, EntityX(camera,true), 6, EntityZ(camera,true), True



Jaydubeww(Posted 2008) [#13]
OK, now that code is getting close, but if I start my player 6 feet above the starting platform and I move off that platform it will still be 6 feet up relative to the starting platform. Help please? and I can't thank you guys enough.


boomboom(Posted 2008) [#14]
well get the players Y position and add 6 to it, then set that as the cameras Y position. Or parent the camera to the player.


Ross C(Posted 2008) [#15]
Your best bet is to do a linepick DOWNWARDS from the characters position.

LinePick EntityX(char,true), EntityY(char,true), EntityZ(char,true),0,-30,0

This will do a linepick from the characters position, downwards 30 units.

Then

If PickedEntity() = 0 then

If this command returns 0, then nothing exists for 30 units behind the characters position, so you can make him fall. I use 30, to make sure nothing is slightly below him. If they is, you can get the distance to the object below, and set the character 6 units above it, like so:

If PickedEntity() = 0 then
; Nothing near exists below
Else
PositionEntity char,EntityX(char,true), PickedY()+6, EntityZ(char,true),true
End if

Make sure you make your level meshes pickable, via the EntityPickMode command. Use the polygon option.

So, doing the will work for you:

LinePick EntityX(char,true), EntityY(char,true), EntityZ(char,true),0,-30,0

If PickedEntity() = 0 then
    ; Nothing near exists below
Else
    PositionEntity char,EntityX(char,true), PickedY()+6, EntityZ(char,true),true
End if



blade007(Posted 2008) [#16]
I like mtnhome3d idea of the plane, very simple, and it gets the job done.


Jaydubeww(Posted 2008) [#17]
Thanks again Ross C. I'm liking mtnhome3d idea too but unfortunatly im using sketchup right now, and its transparency isnt transparent when I convert it into .3ds and use it in blitz. Anyone know how to get blitz to recognize it as transparent? or make that planes alpha 1(or what ever number recognizes it as transparent).


Ben(t)(Posted 2008) [#18]
for stairs, I have a good method is use,

collisions player,walls,2,3


For i=1 To CountCollisions(player)
If x#<>0 Or z#<>0 Then
If CollisionNY#(player,i)>.1 Then gravity#=0
EndIf
Next

this makes it so that if the character is not hitting the ground then the gravity is used, otherwise the character will slide along whatever it is hitting