Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, dr_panther), 1,100 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
in need of help for my movement code #254259
03/02/09 06:19
03/02/09 06:19
Joined: Jun 2007
Posts: 152
Norway
D
Darkyyes Offline OP
Member
Darkyyes  Offline OP
Member
D

Joined: Jun 2007
Posts: 152
Norway
ok first this code works perfectly on flat ground or downwar hills, but when I try to walk/run up slopes it sometimes get stuck for a while, keep holding my left mouse button and keep running my character finally gets up the slope, I've tried making him be higher in the air but it doesnt help.
I dont know what to do.


Code:
#define gravity_constant -2
 // z_smooth controls how smooth the z-adjustment movement is.  
 // Values are 0 through 1, where 0 is more smooth and 1 is not smooth at all
#define z_smooth .0
// Height to float the entity bounding box off the ground
#define my_z_offset 5

action player()
{
	player = my; // I'm the player
	c_setminmax(me);
 VECTOR move_to_vector;		
 var trace_to_ground;
 var distance_to_ground; // the distance between player's origin and the ground
 var z_adjust = 0;
  var distance_moved;
my.albedo=0;
VECTOR temp[3];VECTOR temp2[3];VECTOR temp_target[3];VECTOR pos1[3];VECTOR pos2[3];
var anim_percentage;
var rot_speed = 6; /////new var 
var new_angle;///////new var
vec_set(temp_target,my.x);
while(1)
{
	trace_to_ground = c_trace(my.x, vector(my.x,my.y,my.z-80000), IGNORE_ME|IGNORE_PASSENTS|IGNORE_PASSABLE|IGNORE_SPRITES|USE_BOX); 
	distance_to_ground = trace_to_ground - my_z_offset;
	distance_moved = c_move(me, vector(0,0,move_to_vector.z + (z_adjust * z_smooth)), nullvector, GLIDE|IGNORE_SPRITES|IGNORE_PASSABLE|USE_BOX);
		if ((distance_to_ground > 0) && (distance_to_ground < 3) && (move_to_vector.z < 0))
		{
				z_adjust = (trace_to_ground * -1) + my_z_offset;
				move_to_vector.z = 0;
		}
		else
		{
			
			// If the acceleration of gravity would cause the entity to be moved below the ground, shorten
			// the fall so that the entity is put directly on to the ground.
		
			accelerate(move_to_vector.z, (gravity_constant * time_step), 0);

			
			if (move_to_vector.z < (distance_to_ground * -1))
			{
				// move_to_vector.z = (distance_to_ground * -1) * .3;
				z_adjust = (trace_to_ground * -1) + my_z_offset;
				move_to_vector.z = 0;
			}
		}

///////////////////////////////////////////////////////////////////////////////////////////////////
if(mouse_left == 1 && key_shiftl == 0)
{
	pos1.x = mouse_pos.x;pos1.y = mouse_pos.y;pos1.z = 0;
   vec_for_screen (pos1, camera);
   pos2.x = mouse_pos.x;pos2.y = mouse_pos.y;pos2.z = 300000;
   vec_for_screen (pos2, camera);
   c_trace (pos1,pos2,IGNORE_ME|IGNORE_PASSABLE); //|IGNORE_MODELS
   vec_set(temp_target,target);
   
   
   if(vec_dist(my.x,temp_target.x)>90)
{
	
//vec_set(temp.x,temp_target.x);
//vec_sub(temp.x,my.x) ;
//vec_to_angle(my.pan,temp);
//my.pan = smooth(my.pan, 0.95);

////////////////////////////////////////////////new code//////////////////////////////////////////
   vec_set(temp.x,temp_target.x);
   vec_sub(temp.x, my.x);
   vec_to_angle(new_angle, temp.x);
   if (ang(new_angle - my.pan) < -8) 
   {
   	my.pan -= rot_speed * time_step;
   } 
   else
   {
   	if (abs(ang(new_angle - my.pan)) > 8) 
   	{
   		my.pan += rot_speed * time_step;
      }
   }
   my.tilt=0;
   c_move (my, vector(12*time_step,0 , 0), nullvector, IGNORE_PASSABLE | GLIDE);
   ent_animate(my, "run", anim_percentage, ANM_CYCLE);
   anim_percentage += 10 * time_step;
   }
   
   if(vec_dist(my.x,temp_target.x)<90)
   {
   	ent_animate(my, "stand", anim_percentage, ANM_CYCLE);
   	anim_percentage += 2 * time_step;	
   }
   
}
   else
   {
   	ent_animate(my, "stand", anim_percentage, ANM_CYCLE);
   	anim_percentage += 2 * time_step;
   }
   


camera.x = player.x - 210 * cos(player.pan);
camera.y = player.y - 210 * sin(player.pan); // use the same value (250) here
camera.z = player.z + 130; // place the camera above the player, play with this value
camera.arc = 75;
camera.tilt = -10; // look down at the player
camera.pan = player.pan;


wait (1);


}

}



New to lite-c and gamestudio in general, thank you for reading.
Com, A7 v7.7
Re: in need of help for my movement code [Re: Darkyyes] #254924
03/06/09 13:13
03/06/09 13:13
Joined: Jun 2007
Posts: 152
Norway
D
Darkyyes Offline OP
Member
Darkyyes  Offline OP
Member
D

Joined: Jun 2007
Posts: 152
Norway
no-one that can give me a code snippet on how to solve this?


New to lite-c and gamestudio in general, thank you for reading.
Com, A7 v7.7
Re: in need of help for my movement code [Re: Darkyyes] #255025
03/07/09 00:33
03/07/09 00:33
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
hey,

when you create the character model, make his feet about 1/4 of his body height above below 0,0,0

and remove c_setminmax, this should hopefully solve it

hope this helps

Re: in need of help for my movement code [Re: MrGuest] #255035
03/07/09 07:13
03/07/09 07:13
Joined: Jun 2007
Posts: 152
Norway
D
Darkyyes Offline OP
Member
Darkyyes  Offline OP
Member
D

Joined: Jun 2007
Posts: 152
Norway
hm, ok thanks, but I got a small thought saying that the collisions then is only on the small box am i right?


New to lite-c and gamestudio in general, thank you for reading.
Com, A7 v7.7

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

Gamestudio download | chip programmers | 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