Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,388 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Player sticks on terrain/ #208316
05/26/08 16:47
05/26/08 16:47
Joined: May 2008
Posts: 73
Richmond, VA (USA)
coma_dose Offline OP
Junior Member
coma_dose  Offline OP
Junior Member

Joined: May 2008
Posts: 73
Richmond, VA (USA)
When moving, my player sticks in certain places on the terrain. Here is the player code, it's part KH movement my Mr. Lancaster, with the gravity from the dude that runs Game Beep:

Code:
function pl_character()
{
	player = me;
	
	//local variables
	var move[3];
	var move_result;
	var trace_from[3];
	var trace_to[3];
	var ground_dist;
	var anim_per;
	
	//adjust bounding box
	wait(1);
	c_setminmax(me);
	vec_set(my.min_x,vector(-25,-25,-60));
	vec_set(my.max_x,vector(25,25,60));
	
	//loop
	while(me)
	{
		
		
		temp.x = -1000;
		temp.y = 0;
		if(key_w && !key_s && !key_a && !key_d){temp.x = camera.pan;}
		if(key_s && !key_w && !key_a && !key_d){temp.x = camera.pan + 180;}
		if(key_a && !key_s && !key_w && !key_d){temp.x = camera.pan + 90;}
		if(key_d && !key_s && !key_a && !key_w){temp.x = camera.pan - 90;}
		if(key_w && key_a && !key_d && !key_s){temp.x = camera.pan + 45;}
		if(key_w && key_d && !key_a && !key_s){temp.x = camera.pan - 45;}
		if(key_s && key_a && !key_d && !key_w){temp.x = camera.pan + 135;}
		if(key_s && key_d && !key_a && !key_w){temp.x = camera.pan - 135;}
		
		//calculate directional force
		if(temp.x != -1000){temp.y = 20 * time;}
		move.x = fcos(temp.x,temp.y);
		move.y = fsin(temp.x,temp.y);
		
		//trace floor
		vec_set(trace_from,my.x);
		vec_set(trace_to,my.x);
		trace_to.z -= 500;
		ground_dist = c_trace(trace_from,trace_to,ignore_me|ignore_passents|ignore_passable|ignore_sprites|use_box);
		
		//calculate jumping
		if(key_space)
		{
			if(ground_dist < 5)
			{
				ground_dist = 3;
				move.z = 5;
			}
		}
		
		//gravity
		if(ground_dist > 0)
		{
			accelerate(move.z,(-3 * time_step),0);
			if (move.z < (ground_dist * -1))
			{
				move.z = ground_dist * -1;
			}
		}
		else
		{
			move.z = -1 * ground_dist;
		}
		
		//move player
		move_result = c_move(my,nullvector,move.x,ignore_passable|ignore_passents|ignore_sprites|glide);
		
		//calculate rotation
		if(my.pan != temp.x && (temp.y > 0))
		{
			result = ang(temp.x - my.pan);
			if(result > 0){my.pan += 30 * time;}
			if(result < 0){my.pan -= 30 * time;}
			if(ang(temp.x - my.pan) < 0 && result > 0){my.pan = temp.x;}
			if(ang(temp.x - my.pan) > 0 && result < 0){my.pan = temp.x;}
		}
		
		//rough draft animation
		if(temp.y == 0)
		{
			anim_per += (1 * time_step);
			ent_animate(me,"idle",anim_per,anm_cycle);
			anim_per %= 100;
		}
		else
		{
			anim_per += (move_result * (2 * time_step));
			ent_animate(me,"run",anim_per,anm_cycle);
			anim_per %= 100;
		}
		
		orbit_camera();
		wait(1);
	}
}


The sticking can be easily noticed because the running animation is linked to the c_move result. I am unsure as to whether this has to do with c_move itself or rather the gravity. I have tried multiple movement code types and the result seems the same as far as the sticking is concerned.

Re: Player sticks on terrain/ [Re: coma_dose] #208325
05/26/08 17:33
05/26/08 17:33
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Have a look at the bounding box of your model, hit F11 in the game for that:
Is the bounding box actually _above_ the ground?
If not you probably have to decrease the min_z value:

"vec_set(my.min_x,vector(-25,-25,-60));"

The third value in this row!

Re: Player sticks on terrain/ [Re: Pappenheimer] #208330
05/26/08 17:52
05/26/08 17:52
Joined: May 2008
Posts: 73
Richmond, VA (USA)
coma_dose Offline OP
Junior Member
coma_dose  Offline OP
Junior Member

Joined: May 2008
Posts: 73
Richmond, VA (USA)
Here's the thing: on a flat surface it is above the terrain, but as it ecounters a slope, the bottom corners may dip slightly below, I think that this causes the sticking; however, decreasing the bounding box value results in a different gravity calculation, to the same end. In essesence, decreasing the bounding box value lowers the player into the terrain and the player will still stick on some slopes. I added "-5" to my ground_dist trace and achieved some success, but the sticking still occurs on steep slopes because the corners will still collide with the terrain.

EDIT: I was actually doing some thinking, I'm at work now and can't test it until I get home, but if I decreased the bounding box size by say 10 and then decreased the "-5" to "-10", what I may be left with is a bounding box that is technically off the ground a little and the model being offset to twice that creating the illusion that it is off the ground. I may have phrased this wrong, but I can see the meaning in my mind lol. I will post an update when I give it a test run with corrected code and comments to help other people because I am sure that I'm not the only one with this problem.

EDIT: Er, rather; offset by the same amount...

Last edited by coma_dose; 05/26/08 19:36.
Re: Player sticks on terrain/ [Re: coma_dose] #208390
05/27/08 07:13
05/27/08 07:13
Joined: May 2008
Posts: 73
Richmond, VA (USA)
coma_dose Offline OP
Junior Member
coma_dose  Offline OP
Junior Member

Joined: May 2008
Posts: 73
Richmond, VA (USA)
Tried out my method and it works great! Solves the problem 100%, and like the hydra that this engine seems to be, more problems pop up in its place. My new main problem that will haunt me and keep me from actually publishing a game is that now my player model literally rockets up steep slopes at twice the normal speed. What I need is something that reduces the speed if on steep slopes. I have tried a couple of things with normal.z but nothing seems to work properly. I can't believe that with all the features that this engine seems to have that I have to go on a huge hunting trip seemingly and work my tail off to get a single good feature to work.

Re: Player sticks on terrain/ [Re: coma_dose] #208446
05/27/08 13:34
05/27/08 13:34
Joined: Sep 2003
Posts: 733
Whitefish, Montana
JazzDude Offline
User
JazzDude  Offline
User

Joined: Sep 2003
Posts: 733
Whitefish, Montana
Examine the polygons of your terrain. Long narrow polys sometimes cause sticking problems.

Re: Player sticks on terrain/ [Re: JazzDude] #208457
05/27/08 15:07
05/27/08 15:07
Joined: May 2008
Posts: 73
Richmond, VA (USA)
coma_dose Offline OP
Junior Member
coma_dose  Offline OP
Junior Member

Joined: May 2008
Posts: 73
Richmond, VA (USA)
I don't have any long narrow polys, also this happens on every terrain that I have ever used. It's a serious bottle neck.

Re: Player sticks on terrain/ [Re: coma_dose] #208462
05/27/08 15:27
05/27/08 15:27
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Can you post a screenshot with the bounding box visible, before and after the correction?

Hm, I'm a bit irritated. I thought Bret's code carries the model's box _above_ the ground, but this doesn't:
"if(ground_dist > 0)"

I don't use the code, so I'm just guessing:

ground_dist IMO must be higher the zero, about 20 or so, depending on the models size and the slopes etc.. If it is zero the collision box always touches the ground, but you should avoid that.

Re: Player sticks on terrain/ [Re: Pappenheimer] #208474
05/27/08 16:26
05/27/08 16:26
Joined: May 2008
Posts: 73
Richmond, VA (USA)
coma_dose Offline OP
Junior Member
coma_dose  Offline OP
Junior Member

Joined: May 2008
Posts: 73
Richmond, VA (USA)
You're irritated? LOL! No it doesn't carry the box above the ground however what I did does carry the box above the ground. The problem now is that, when on slopes, the player can move fast. I just need something to slow the player down.



PS: I have noticed that if you ever want to stop a discussion dead in its tracks, mention jerky movement with c_move lol. Works every time.

Re: Player sticks on terrain/ [Re: coma_dose] #208488
05/27/08 17:27
05/27/08 17:27
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
:?
Does this mean that the original problem is solved?

(correction of a sentence in my former post: "ground_dist IMO must be higher _than_ zero, ")

Re: Player sticks on terrain/ [Re: Pappenheimer] #208516
05/27/08 19:12
05/27/08 19:12
Joined: Feb 2005
Posts: 647
Williamsburg, VA USA
draculaFactory Offline
User
draculaFactory  Offline
User

Joined: Feb 2005
Posts: 647
Williamsburg, VA USA
The problem with the sticking is solved by way of increasing min_z from -60 to -55 and then adding +5 to the end of the c_trace to get the distance to ground. The result is that the bounding box hovers off of the ground and ground_dist thinks it is on the ground because of +5.

Solving this problem created a new one. The player model can move up steep inclines at a speed that is much faster than normal lol. I just need something that decreases the speed while on a steep incline to make it hard to move up steep slopes, and if the slope is too steep, the player can't move up at all.


Making dreams come true... And being erroneously accused of software piracy by Conitec in the process.
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1