Quick jump code issue

Posted By: Tman

Quick jump code issue - 02/25/10 16:11

I have a jump code and it works great for when the player is not moving but when I am running and then jump he seems to glide and not land on his feet, anyone has ideas? Here is a portion of my code.
Code:
// adjust entity to the ground height, using a downwards trace
		if(c_trace(my.x,vector(my.x,my.y,my.z-5000),IGNORE_PASSABLE|IGNORE_ME) > 0)
		dist_down= my.z + vFeet.z - hit.z; // always place player's feet on the ground
		else
		dist_down = 0;	
		
	   
	   if((dist_down > 0))
		{
		 	
		 dist_down = clamp(dist_down,100,accelerate(speed_down,-nc_gravity * time_step,0.1));
		 
		}
		else
	   {
	   	//do the speed down to equal 0 so that he snaps to the ground
	   	speed_down = 0;
	   	if((dist_down + speed_down)> 0)
	   	{
	   		speed_down = - dist_down - 0;
	      }
	      if(key_space == 1)
	      {
	      	jump_target = jump_height * time_step;
	      }
       }
       if(jump_target > 0)
       {
       	speed_down = (sqrt((jump_target)* nc_gravity))*time_step;
         	
       	jump_target -= speed_down ;
        }



This is the jump portion any help is appreciated.
Posted By: Tman

Re: Quick jump code issue - 02/25/10 16:53

I need to amend my post and this may be the wrong place to put it, I have the jump working perfectly now, but I have a custom model for terrain that was made in Maya and the bounding box surrounds the terrain instead of the terrain being the solid object how do I correct this and if this is the wrong place to ask forgive me and point me in the right direction.
Posted By: Superku

Re: Quick jump code issue - 02/25/10 17:31

Set its POLYGON flag.
Posted By: Tman

Re: Quick jump code issue - 02/25/10 18:22

I set that but it is like the bbox is covering the entire ground model it is like 500 guads high. I need to have it like a model that is created in the med or the wed?
Posted By: Superku

Re: Quick jump code issue - 02/25/10 19:03

I don't understand, could you please post a screen shot and describe your problem again in other words?
Posted By: Gamesaint762

Re: Quick jump code issue - 02/25/10 20:45

Im working with Tman so here is the screenshot for the level hes talking about. Thanks!



The player runs by pressing forward key. Press space bar and he does jump animation, however when he returns to the ground instead of doing the landing animation and then going into a run he just stops and then glides across terrain. Its as if he never gets back down to the ground.
Posted By: Tman

Re: Quick jump code issue - 02/25/10 21:34

See the bbox is like surrounding the terrain but the terrain is low and the box spreads all the way up high but if you build a model in the wed the bbox or collision points I might say are the model it self it doesn't build a box around the model.
If that makes sense.
Posted By: Superku

Re: Quick jump code issue - 02/25/10 22:38

Ok. I've understood your problem as follows:
You've made a terrain in an extern program (Maya), that is not an A7-terrain but an A7-model. You want it to behave like a terrain.
AFAIK you only have to set(terrain,POLYGON). When "polygon" is set, the model still needs a bounding box. When c_trace/c_move hits the bounding box, then (!) the engine will check the polygonal shape and if there is contact or not. So it's fine if the bbox is a little bit bigger than the model itself.

Here is a code that I've written some days ago for someone else, so I know that it works (you may test the current model/ situation with it):

Click to reveal..

Quote:
action player_walk() {
var anim_percent = 0;
var grounddist, key_space_released = 0;
VECTOR speed,temp;
vec_set(speed,nullvector);
wait(1);
vec_set(temp,vector(-15,-15,-20)); // die bounding box setzen
vec_scale(temp,my.scale_x); //falls der spieler im level eine andere größe als 1 hat
vec_set(my.min_x,temp);

vec_set(temp,vector(15,15,20)); // die bounding box setzen
vec_scale(temp,my.scale_x); //falls der spieler im level eine andere größe als 1 hat
vec_set(my.max_x,temp);
my.z += 232;

while(1) {

if(!key_space) { key_space_released = 1; } // endlose Sprungwiederholung bei gedrückter Taste verhindern

if(key_a || key_d) {
my.pan = 180*key_a;
anim_percent += 8*time_step;
ent_animate(me, "run", anim_percent, ANM_CYCLE);
}
else {
anim_percent += 4*time_step;
ent_animate(me, "stand", anim_percent, ANM_CYCLE);
}

speed.x += (45*(key_d-key_a)-speed.x)/3*time_step; // sanftes beschleunigen

grounddist = c_trace(my.x,vector(my.x,my.y,my.z-150),IGNORE_ME | USE_BOX);
grounddist = clamp(grounddist+150*(!trace_hit),-5,150);


if(grounddist < 10 && speed.z <= 0) {

my.z -= grounddist-5;
speed.z = 0;
if(key_space && key_space_released) {
speed.z = 50;
}
}
else { speed.z += maxv((-60-speed.z)/5,-7)*time_step; }



c_move(my,nullvector, vector(speed.x*time_step,0,speed.z*time_step),GLIDE);


//Cameraposition
camera.x = 100+my.x;
camera.y = -2500;
camera.z = 400+my.z;
camera.pan = 90;
camera.tilt = -5;
wait(1);
}
}


Next, try using the polygon flag in trace_mode (I've never used it before, pls check the manual).
Then try it with a normal A7-terrain from MED.


EDIT: I'm not sure what your code should do:
Code:
// adjust entity to the ground height, using a downwards trace
		if(c_trace(my.x,vector(my.x,my.y,my.z-5000),IGNORE_PASSABLE|IGNORE_ME) > 0)
		dist_down= my.z + vFeet.z - hit.z; // always place player's feet on the ground
		else
		[b]dist_down = 0;[/b]
		
	   
	   if((dist_down > 0))
		{
		 	
		 dist_down = [b]clamp(dist_down,100,accelerate(speed_down,-nc_gravity * time_step,0.1));[/b]
}



The limits in clamp are -,+ not +,- if I read your code right.
Then why do you set down_dist = 0; ? (I did not spend much time on understanding it, though)

Have you tested the code with block geometry?

Then, try if(down_dist > 5) { ... }.
Posted By: Gamesaint762

Re: Quick jump code issue - 02/26/10 13:58

The code we are currently using works fine with blocks.. Seems strange that he runs and collision is fine when standing but not after jumping? Strange...
Posted By: Superku

Re: Quick jump code issue - 02/26/10 14:23

Please read my last post again and test the points that I've mentioned.
Posted By: Tman

Re: Quick jump code issue - 02/26/10 15:08

Hey thanks for all the help SuperKu.
I have tried to do the dist_down > 5 I get the same results when I run and then jump, so that is not the issue I was looking at all the other mdls created in 3dgs and they are .hmp files for the terrains, so my question becomes how do you take a mdl that you created in Maya and then covert it to a .hmp or terrain file?
Posted By: Rich

Re: Quick jump code issue - 02/27/10 06:25

You can't really convert a mdl to a terrain heightmap (unless maybe you made a gray scale overview map of it and imported it to MED or something).

If you assign the terrain model the polygon flag like Superku said (click the polygon checkbox in WED, of by script like said above) the c_ functions will use polygon collision on the model, so it should behave similar to a terrain. You could also do with with any model you want to use for geometry where blocks won't cut it. In some cases it may be better to use invisible blocks for collision or to keep entities out of complex geometry.

Entity running up a model using c_move. Model has polygon set.


Hope that helps. laugh

Another picture showing a model being used like a terrain.

Posted By: Tman

Re: Quick jump code issue - 02/28/10 17:09

That helps alot, I thought the model I was using for terrain was to have polygon set to it only, now I get. I have one more issue but I do that other problem fixed. How do I set my model to land when it moving and I am jumping on a hill or slope? When I press the jump key and move on a flat surface he lands correctly but when I am moving and I press jump on a hill or slope he stay in the air until he gets to a flat surface. How do I change that?
Posted By: Rich

Re: Quick jump code issue - 03/01/10 16:30

do you mean that it slides down the slope when you land on one?

If so then that would be that your gravity is kicking in and needs to be adjusted. I had this problem for a while, gravity will drag the object down the slope.

If not then I'm not quite sure what you mean by moving on a slope?

Good luck.
Posted By: Tman

Re: Quick jump code issue - 03/01/10 17:18

That is exactly right Rich, when he is going up or down the slope and I press jump he stays elevated until I hit a flat surfae but I think that I fixed it now. Thanks for the reply.
Posted By: Rich

Re: Quick jump code issue - 03/01/10 18:05

No problem, seeing that you've been hitting snags with movement (as I did for a long time, still do) maybe you would like to look at this "tutorial in progress" I was writing (I stopped).

http://www.ninjawarriors.net/pages/rich-lockard/a7-movement-tutorial-beta/page1.php

Its not complete, probably has a bunch typos, but maybe it will help you somewhere. It stops at gravity, no jump code or anything like that, but I think setting a 'ground offset' will help you with slopes. You could set your gravity to 'turn on' anytime the trace hits a slope with a certain normal (seeing your other post about adjusting the tilt of the entity, same thing).

Let me know what you think, I think I suck at this so wink

Good luck.
© 2024 lite-C Forums