camera bump/jump

Blitz3D Forums/Blitz3D Beginners Area/camera bump/jump

Ruz(Posted 2003) [#1]
Just wondering how to do this. i want it so my camera( player view) jumps up a set distace if I bump in to an obstacle(mesh). this Is just a test really. Its a bit flawed in that if you bump in to a wall you wll still jump or perhaps you will jump/rise constantly since you are always in contact with the mesh/terrain as you are walking

At present you will jump if you press the alt key.
the problem also is that if you keep your finger on alt you keep rising.

If KeyDown( 205 )=True Then TurnEntity camera,0,-1.4,0
If KeyDown( 203 )=True Then TurnEntity camera,0,1.4,0
If KeyDown( 208 )=True Then MoveEntity camera,0,0,-0.5
If KeyDown( 200 )=True Then MoveEntity camera,0,0,0.5
If KeyDown (30)=True Then MoveEntity camera,0,0.3,0
If KeyDown (44)=True Then MoveEntity camera,0,-0.3,0

TranslateEntity camera,0,-1,0; gravity

If KeyDown (56)=True Then TranslateEntity camera,0,1.5,0


WolRon(Posted 2003) [#2]
What exactly is your question? I got this out of it: i want it so my camera( player view) jumps up a set distace if I bump in to an obstacle(mesh).

You should be more specific. HOW do you want it to jump?
Instantaneous leap from current pos. to current pos. + some amount in Y?
Constant elevation by incrementing Y value over and over.
Or did you actually mean that you want it to jump up a certain distance and then fall back down?

In the case of jump up/fall down, you need a seperate variable to keep track of your vertical acceleration. When you jump you set this value to anything greater than the downward force of gravity ( -1.0 in your code sample) such as 2.0. Add this value to gravity every loop and then decrement this acceleration variable every loop by a certain amount (say -.02).
This makes the player jump up fast at first and then slowly come to a crest after which he/she slowly starts coming back down and then eventually falls down fast. Once the player has reached the ground again, set this acceleration variable back to zero ( to prevent it from acting as another force of gravity ).

Keep in mind that while the player is in mid air, the pressing of the 'jump' key will cause the player to jump again, so you must avoid that by not allowing a second jump to occur until the player has contacted the ground once again.

If this is not what you were asking then try rephrasing your question.


Ruz(Posted 2003) [#3]
i want a fast out , slow in to the rising curve, accelerating back down. Hope thats clear.Whether or not I use
the alt key to jump or jump aotomatically, i just want it to look natural

I am on the verge of understanding what you are saying, but it may take me a while to implement it.
For a new guy its hard to go from the thought to the deed without sufficient grasps of the syntax/processes etc

I am learning still. Yeah i was kind of vague, because i was hoping someone might add suggestions as to how i could make my camera work better, but I will clarify more in future.

cheers


Stevie G(Posted 2003) [#4]
Why not use this physics formula for the jump, incrementing the 't' once the jump is initiated until you land :-

S=ut+0.5*a*(t^2)

Where t=time, u=initial upward velocity and a=acceleration (in your case gravity), S=displacement (in your case the Y position)


To test what I'm on about :-

a=-9.8
u=60
s=0

repeat
t=t+.01
s=u*t+(a*.5)*(t*t)

;add a bounce if you hit the ground
if s<0 then s=0:u=u*.25

[DRAW YOUR OBJECT @ x,y+s,z position]

until s=0 and u < 7.5


Ruz(Posted 2003) [#5]
Thanks for thatm Steve G, I will try and get it up and running. the bounce is a great touch too.
I will probably get stuck though, this programming stuff is tougher than I thought.