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,619 guests, and 5 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
c_move - vents and ducking #376081
06/29/11 22:42
06/29/11 22:42
Joined: Mar 2003
Posts: 1,524
Canada
Stansmedia Offline OP
Serious User
Stansmedia  Offline OP
Serious User

Joined: Mar 2003
Posts: 1,524
Canada
My player entity is moving with c_move, and like the basic example in the help doc it does a trace down and moves down if it's too high. Now when I walk into where a vent/grate is, the play starts to slide downward. I'm guessing it's because of the ellipsoid hull, which is no biggy. Problem is I can't clue in on a way to keep the entity at a certain height above the ground. If i use c_move to send it up the player starts bobbing up and down. if I set the players z position directly (if < hit.z + 32 ... my.z = hit.z + 32) the player slips into the walls. I think what I need is some code that smooths out the upward c_move so it doesn't jump the player over that threshold of 32 units above the hit surface. Any suggestions?


Decessus - 80% done. 100% abandoned.
GET MY ANDROID GAME! https://play.google.com/store/apps/details?id=com.lasertrain.zspinballfree&hl=en
Re: c_move - vents and ducking [Re: Stansmedia] #376086
06/29/11 23:04
06/29/11 23:04
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Here, a basic player/ gravity code that keeps a distance to the ground:

Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////

var key_space_released = 0;
var gravity_acceleration = 5;

// basic camera code
void camera_update(ENTITY* ent) {
	
	VECTOR temp;

	camera.pan = ent.pan;
	camera.tilt = -5;
	
	vec_set(temp,vector(-100,0,4));
	vec_rotate(temp,camera.pan);
	vec_add(temp,ent.x);
	vec_set(camera.x,temp);

}


action act_player() {
	
	player = me;
	c_setminmax(my);
	set(my,SHADOW | UNLIT);
	my.skill4 = 8; // height above ground, should not be equal or below zero - increase min_z (min_z is negative) instead, if necessary
	
	while(1) {

		// horizontal movement

		my.pan += (key_a-key_d)*10*time_step;
		my.skill1 += ((key_w-key_s)*15 - my.skill1)/4*time_step; // makes player accelerate and stop smoothly
		c_move(me,vector(my.skill1*time_step,0,0),nullvector,GLIDE);


		// vertical movement and gravity

		result = c_trace(my.x,vector(my.x,my.y,my.z-200),IGNORE_ME | IGNORE_PASSABLE | USE_BOX);
		result += !trace_hit*200; // when !trace_hit ist true, c_trace returns 0, that's why we have to add some quants (f.i. the maximum trace distance)
		
		if(trace_hit) my.skill3 = target.z; // see 25 lines below
		else my.skill3 = -9999999;

		if(result > my.skill4 || my.skill2 > 0) {
			
			my.skill2 -= gravity_acceleration*time_step;
			my.skill2 = maxv(my.skill2,-80);
			c_move(me,nullvector,vector(0,0,my.skill2*time_step),GLIDE);
			
		}
		else {
			
			my.skill2 = 0;
			if(key_space) {
				
				if(key_space_released) {
					key_space_released = 0;
					my.skill2 = 35;	// jump strength
				}
				
			}
			else key_space_released = 1; // no infinite jumping, release space (while on ground) for a new jump
			
		}
		
		my.z = maxv(my.z,my.skill3+my.skill4-my.min_z); // make sure player's feet stay above ground
		
		camera_update(my);
		
		wait(1);
	}
	
}

void main() {
	
	fps_max = 60;
	video_mode = 10;
	level_load("tip3.wmb");
	ent_create(CUBE_MDL,nullvector,act_player);
	
}



I don't think I got the vent/ grate part right. In general, it's probably a better idea to set some objects that may be difficult for your player code to handle passable and use simple invisible collision shapes/ models.
When you're working on a shooter, you can use c_ignore and groups instead of the passable flag to still allow polygonal collision on those objects.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: c_move - vents and ducking [Re: Superku] #376094
06/29/11 23:36
06/29/11 23:36
Joined: Mar 2003
Posts: 1,524
Canada
Stansmedia Offline OP
Serious User
Stansmedia  Offline OP
Serious User

Joined: Mar 2003
Posts: 1,524
Canada
I have not tried this but I have a feeling that setting the players Z directly will bring about the same problem. The hull will worm its way down and the trace will bump it up to it's designated height, getting it stuck in the wall/ceiling.


Decessus - 80% done. 100% abandoned.
GET MY ANDROID GAME! https://play.google.com/store/apps/details?id=com.lasertrain.zspinballfree&hl=en
Re: c_move - vents and ducking [Re: Stansmedia] #376096
06/29/11 23:40
06/29/11 23:40
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
No, that's not the case if I understood you correctly. Be aware that the complete while loop is executed before the object is rendered.

Quote:
The hull will worm its way down and the trace will bump it up to it's designated height, getting it stuck in the wall/ceiling.

Can you explain your problem in different words?


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: c_move - vents and ducking [Re: Superku] #376104
06/30/11 00:59
06/30/11 00:59
Joined: Mar 2003
Posts: 1,524
Canada
Stansmedia Offline OP
Serious User
Stansmedia  Offline OP
Serious User

Joined: Mar 2003
Posts: 1,524
Canada
Well, with glide mode on, you can snag a corner and still slowly work your way around right? Well that's whats happening with a ceiling plane thats above the entities origin. It's gliding down the z access trying to make its way into the vent. I move forward and push into a wall that has a vent without crouching, and wiggle my pan around and then I'm stuck in the wall. I turn around and move forward and I come out of the wall. I'm not modifying the player.z at all, simply moving it around with c_move. If players not crouching the c_move moves it to 32 units about the ground, if crouching makes its way to 16 units.


Decessus - 80% done. 100% abandoned.
GET MY ANDROID GAME! https://play.google.com/store/apps/details?id=com.lasertrain.zspinballfree&hl=en
Re: c_move - vents and ducking [Re: Stansmedia] #376109
06/30/11 03:19
06/30/11 03:19
Joined: Mar 2003
Posts: 1,524
Canada
Stansmedia Offline OP
Serious User
Stansmedia  Offline OP
Serious User

Joined: Mar 2003
Posts: 1,524
Canada
And C_Rotate saves the day! I threw in c_rotate instead of my.pan and that seemed to fix the going into the wall problem. I used moveforce.z = ((my.z - floorz + 32 - (crouchamount)) * -0.1; to make a smooth transition from crouching to standing with out the bobbing jitter - without screwing with the z position directly or setting new collision hull dimensions. NOW... ugh lol. I can stop the player from worming into vents without crouching, but the only work around i've found is disable_z_glide... which totally screws the movement currently. Perhaps if I did two seperate c_moves... One just with X - Y movement with disable_z_glide and another just with Z movement but with z glide... Hmmm.


Decessus - 80% done. 100% abandoned.
GET MY ANDROID GAME! https://play.google.com/store/apps/details?id=com.lasertrain.zspinballfree&hl=en
Re: c_move - vents and ducking [Re: Stansmedia] #376114
06/30/11 07:41
06/30/11 07:41
Joined: May 2009
Posts: 5,377
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,377
Caucasus
Dude, try my example, here:
Download link
It's very simple to learn, and there is a crawling example as well.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung

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