simple jump code needs some tweaking...

Posted By: Doc_Savage

simple jump code needs some tweaking... - 04/11/11 07:25

ok ive learned enough to make my own jump code. but it has a bit of a problem. i can hold the button down and you will bounce up and down until you release the button, at which time youl fall very fast to the ground. and if you jump onto say, a box, it will kinda "reset" your height as if you jumped ON the box before falling back to the ground. (i hope that makes sense :p) id love to get help on these problems.

anyways heres the code i made

Code:
if(key_space)
	{
		dist.z = 5;
	wait(-0.66);	
		dist.z = 0;
	}



i know its not much but it kinda does the job tongue

i hope you guys can help smirk
Posted By: Doc_Savage

Re: simple jump code needs some tweaking... - 04/12/11 18:58

anyone??
Posted By: Uhrwerk

Re: simple jump code needs some tweaking... - 04/12/11 20:14

Seriously, what is this code supposed to do? It just sets an entities z coordinate to 5, waits 2/3 seconds and resets it to 0 if space is pressed. What do you intend it to do? Where ist the rest of the code? Context? Question?
Posted By: Doc_Savage

Re: simple jump code needs some tweaking... - 04/14/11 04:22

did you read the whole post? its a makeshift jump animation, id like to know how to get help on the problems i stated. or possibly make it better altogether. bear in mind this is in the "starting with GameStudio" section. and i am indeed starting.
Posted By: Uhrwerk

Re: simple jump code needs some tweaking... - 04/14/11 11:09

It's not a problem that you're a beginner. But you need to offer more information on your problem. The code fragment you posted cannot be all of your code. How does the rest work? How do you move in your game? How do you apply gravity. What is the variable dist and where else is it used? What kind of game is it at all that you make.
Posted By: Doc_Savage

Re: simple jump code needs some tweaking... - 04/15/11 04:14

that code fragment is everything that controls jumping aside from this:

Code:
function handle_gravity()
{
	result = c_trace(my.x,vector(my.x,my.y,my.z-1000),IGNORE_PASSABLE|IGNORE_MODELS|USE_BOX);
	if(result > 1)
	{
		dist.z -= 1 * time_step;
	}
	else
	{
		dist.z = 0;
	}
}



its a.. well. lets just call it a first person shooter for now. movement is separate. this and the code fragment above are all that have to do with jumping. perhaps with this, you can help me to solve the problems i have? maybe i need a new code for jumping entireley or somthing. i know its not really jumping. it just pushes the player up a bit. lol

i do appreciate you taking the time to look at this and help me. if you need any more code let me know.
Posted By: Uhrwerk

Re: simple jump code needs some tweaking... - 04/15/11 15:56

Ok, now we've got a second code snippet that writes values into your distance vector. The most important thing is still missing, namely the part where the actor is moved according to dist.z. It's also important how your first code fragment is called. In order to help you we need a more complete view of the problem.

Imagine you're assembling a clock and you've come to a problem there. Now you're asking in a forum for help and show two photos of two small gears. That is not enough. The other members need to understand how the different gears of your clock come together and interact. ;-)
Posted By: Doc_Savage

Re: simple jump code needs some tweaking... - 04/15/11 20:35

ah i see. ok. so what part do you need exactly? the entire movement code is here:
Code:
function handle_movement()
{
		if(key_shift)
	{
		dist.x = 25 * (key_w - key_s) * time_step;
		dist.y = 25 * (key_a - key_d) * time_step;
	}
	else
	{
		dist.x = 15 * (key_w - key_s) * time_step;
		dist.y = 15 * (key_a - key_d) * time_step;
	}
			if(key_space)
	{
		dist.z = 5;
	wait(-0.66);	
		dist.z = 0;
	}


}




what else? ill get it all together
Posted By: Uhrwerk

Re: simple jump code needs some tweaking... - 04/15/11 21:26

Ok, I think I'm starting to understand your overall approach. I assume handle_movement() is called every frame? And I assume you have somewhere else in your code a function that moves your player entity by the distance stored in the dist vector?

If that is the case I don't recommend using a wait inside the handle_movement function. If dist.z = 0 takes effect depends on the order of the functions in the internal scheduler.

Could you please try to exactly write down which part of the code's behaviour you want to change?
Posted By: Doc_Savage

Re: simple jump code needs some tweaking... - 04/16/11 01:47

i only put the wait in there after to try and get it to only jump once. i dont know how to get it to jump only once when you hold the key down. ok basically i would love to get a jump code basically. the first segment of code was my weak attempt at a jump code lol. it was the only way i knew how to make one haha
Posted By: Uhrwerk

Re: simple jump code needs some tweaking... - 04/16/11 02:03

Your approach is to directly influence a distance vector and move the player according to that vector. That is a very simple approach. Another simple yet much better looking approach is to work with forces and speeds.

It basically goes like this:
1. Assemble a force vector - basically the way you already did by checking if the wasd or arrow keys are pressed and adding an extra boost for the shift key. But this time you do not multiply with time_factor.
2. Do an extra check for the players height. Is the player a certain distance over the ground? If so then apply gravity, i.e. a force downwards. If not, well, then check if the jump key is pressed and if so add an upwards force.
3. You have got a second vector called speed. Initially all speed components are zero. Now you can accelerate the current speed by the force vector you just assembled. You get a current speed and can move your player by this speed vector.

For accelerating you can use the function vec_accelerate. That is still relatively simple, but the results should be much better. Does that give you the idea what to do next?
Posted By: Doc_Savage

Re: simple jump code needs some tweaking... - 04/16/11 02:12

yes it does. i will try to start on this now. i think i have done number 2 in handle_gravity. is that where i should put the jump code then?

ill have to research how to assemble this. haha. but its clear what i need to do.

when i assemble the force vector, dows that mean i redo handle_movement?
Posted By: Uhrwerk

Re: simple jump code needs some tweaking... - 04/16/11 18:09

Originally Posted By: Doc_Savage
is that where i should put the jump code then?

Either there or in handle_movement. Note that you don't have to write absolute values into variables. For instance if you detect the player is in the air you can also subtract a value from the force vector like: "force.z -= 9,81;". You only have to pay attention then, that you reset the force vector after every acceleration of the speed vector.

Originally Posted By: Doc_Savage
when i assemble the force vector, dows that mean i redo handle_movement?
Basically yes. You can keep the base idea of handle_movement but have to do some changes there...
Posted By: Doc_Savage

Re: simple jump code needs some tweaking... - 04/17/11 00:55

ok ill be honest. i have no idea how to do that.. lol.. just wasnt covered in the workshops and there are no tuts. maybe i can request one in the tutorials section...
Posted By: Uhrwerk

Re: simple jump code needs some tweaking... - 04/17/11 02:24

Just tell me where exactly your problem is and maybe I can give you a kick off. :-)
Posted By: Doc_Savage

Re: simple jump code needs some tweaking... - 04/17/11 02:29

i need to know how to create a whole new REAL jump code. thats pretty much it. one with forces and all that stuff you told me.

im so dumb lol.
Posted By: FoxHound

Re: simple jump code needs some tweaking... - 04/17/11 04:43

You need to learn how to play a bit more when making games. Try this, have your jump keep happening even if you dont let go of the key. This way you can see how long it takes for the player to get off the ground. If it is to much or too little. Put more "god like" controls such as this when you are debugging and you figure this out a lot faster.
Posted By: Doc_Savage

Re: simple jump code needs some tweaking... - 04/17/11 04:48

ive gotten to this stage beleive it or not. now how can i cause the code to stop a certan amount of time after i press the key?
(and basically have to press it again to jump again)
i know theres got to be some sort of code word to do it. i tried the wait(1); one, but it just dosent seem to work.

see, im more of a game artist not a tech guy. but i want to learn both laugh


i am quite happy with the discoveries ive made though, ive given my player the ability to regenerate health, as well as a GREAT death code. i love learning new things. im sorry to see the workshops only ended with 25 smirk
Posted By: FoxHound

Re: simple jump code needs some tweaking... - 04/17/11 17:02

Don't feel bad. Jumping is one of the hardest "easy" things to do in a game. It also what usually marks when someone can call themselves a programmer. Because you have to look at something from real life and mimic it.

When you Jump you put upward force on your body. The entire time gravity is working against that force, even when you are going up. What is happening is gravity is reducing that force amount until it becomes zero. That is the top of your jump. Then you fall back down. But what seems to be missed is that at the start of your jump you are moving the fastest. At the end of your jump when you hit the ground you move the fastest. So for once instance at the height of that jump, from when you go from moving up to moving down, you are motionless, suspended in air.
Posted By: Doc_Savage

Re: simple jump code needs some tweaking... - 04/18/11 01:45

i cant figure out a darn thing. im too stupid to figure this out. no matter what i cant get past using dist.z = 5; NOTHING ELSE WORKS im getting very irritated. cant SOMEONE let me know how to start making a REAL jump code? im deleting everything i have on jump (a whopping 3 LINES!!! WOOHOOO SO MUCH WORK!) until i can understand what you guys are talking about. ive tried putting in speed, force, vec_accelerate NOTHING FRIGGIN WORKS AT ALL and theres no tutorials on this! theres NOTHING about jumping in the workshops, the manual. OR the aum magazine! ive even looked at past posts about jump code but i cant make heads or tails of it!! I SUCK!!!!
Posted By: FoxHound

Re: simple jump code needs some tweaking... - 04/18/11 18:19

What you need to have is a gravity code in place. Easiet way is to trace from the player to the ground and if there is space between the feet of the player and the ground you move them down using c_MOVE


Now when you press the space bar have it call a function that puts upward force on the player. Each frame have that number dropped down a bit. Use c_move to move the player up.

This should give you tw0 sets of c_move which is not a good thing but it will work and the framerate slow down, if there is any, would be very low to none at all and will work fine until you get further in codding.

Now if gravity is at -5 then the up jump should be 15.
Posted By: Doc_Savage

Re: simple jump code needs some tweaking... - 04/18/11 19:01

ok i have a gravity code in place:
Code:
function handle_gravity()
{
      result = c_trace(my.x,my.y,my.z-1000),IGNORE_PASSABLE|IGNORE_MODELS|USE_BOX);
if (result > 1)
{    dist.z -= 5 * time_step;
}
ELSE
{
    dist.z = 0;
}
}



does this look alright? or should i replace dist.z with c_move?

the only thing the jump function has is:
Code:
dist.z += 5;




i guess ill start there tongue trying to add c_move to one of those.. and, sorry for my last post. it was late night and i was frustrated lol.. i guess it can get like that sometimes tongue
Posted By: FoxHound

Re: simple jump code needs some tweaking... - 04/18/11 22:43

You're getting there. Main thing is just to try and not ask if it will work. There is info I don't have. Like how far is it from your model's origin to the bottom of the lowest vertex to know how much distance you should move the mesh to get it to the ground.


function blah_name()

{
var blah = 15;
while(blah){
blah -= 1;
//this is moved in the world movement
c_move(me, blah vector(0,0,blah * time_step), blah

wait(1);//this should move the player up. Adjust the 15 and the -1 to see what works best
}



}
Posted By: Doc_Savage

Re: simple jump code needs some tweaking... - 04/19/11 03:32

ok ive fiddled with this template you supplied.

Code:
function jumpyoubastard()
{
var jumpheight = 5;
while(key_space == 1){
//this is moved in the world movement
c_move(my,dist,vector(0,0,jumpheight * time_step), IGNORE_PASSABLE|GLIDE);
wait(1);//this should move the player up. Adjust the 15 and the -1 to see what works best
}



}



i took out the -= 1; because thats already in place in my handle_gravity code.

ive got some movement i just need to figure out why if i hold the jump button down it causesl:
1: me to go to the top and slowly fall down
2: me to move really fast using the movement keys.

© 2024 lite-C Forums