Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,498 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Please help. #310209
02/13/10 18:25
02/13/10 18:25
Joined: Oct 2009
Posts: 60
T
Tman Offline OP
Junior Member
Tman  Offline OP
Junior Member
T

Joined: Oct 2009
Posts: 60
Hey guys,
Trying to get some scripting help if possible, I have my guy jumping but landing him and make the camera stop jerking seems to be the issue now if any one could look at my code and tell me how to fix this I would appreciate that alot, you just don't know but here is my code.
Code:
while(1)
	{
		var dist_down;
		// adjust entity to the ground height, using a downwards trace
		if(c_trace(my.x,vector(my.x,my.y,my.z-5000),IGNORE_ME | IGNORE_PASSABLE | USE_BOX) > 0)
		dist_down= my.z + vFeet.z - target.z; // always place player's feet on the ground
		else
		dist_down = 0;	
	   if(dist_down > 0)
		{
		dist_down = clamp(dist_down,0,accelerate(speed_down,10,0.1));
		ent_blend("land",25,75);	
		}
		else
	    speed_down = 0;
	    
			//move the entity forward
			var distance =(key_cuu)* 25 *time_step;
			distance = sign(distance)* (abs(distance) + 0.5 * dist_down);
			c_move(me,vector(distance,0,0),vector(0,0,-dist_down),IGNORE_PASSABLE |GLIDE);
			
			//rotate player with the left and right keys
			my.pan += (key_cul-key_cur)*5* time_step;
			
		
      //default state
		if(my.STATE == 0)
		{
			my.ANIMATION += 2 *time_step;
		   ent_animate(me,"idleSWA",my.ANIMATION,ANM_CYCLE);
			
		}
		//the run state without the sword in hand
		if(my.STATE ==1)
		{
			

			ent_blend("runWS",25,45);
			//animate the player
			my.ANIMATION += 15 * time_step;
			ent_animate(me,"runWS",my.ANIMATION,ANM_CYCLE);
					
		}
		//pressing the move key to make him run with out the sword
		//changing his state
		if((key_cuu == 1)&& my.STATE == 0)
		{
			my.ANIMATION = 0;
			my.STATE = 1;
		}
		else if((!key_cuu)&& my.STATE == 1)
		{
			my.ANIMATION = 0;
			my.STATE = 0;
		}

	  //take the sword out and put it in the hand.
		if(my.STATE ==2)
		{
			my.ANIMATION += 5 *time_step;
			ent_animate(me,"takeSWO",my.ANIMATION,0);
			//blend the state from taking out the sword 
			//to the idle.
			if(my.ANIMATION > 100)
			{
			ent_blend(my.STATE = 4,0,50);
			}
				
		}
		//run with the sword in his hand
		if(my.STATE == 3)
		{
         
			ent_blend("run",25,45);
			//animate the player
			my.ANIMATION += 15 * time_step;
			ent_animate(me,"run",my.ANIMATION,ANM_CYCLE);
			
			
		
		}
		//idle with the sword in hand
		if(my.STATE == 4)
		{
		 
			my.ANIMATION += 2 *time_step;
		  ent_animate(me,"idleSWI",my.ANIMATION,ANM_CYCLE);
			
		}
		//putting the sword away
		if(my.STATE == 5)
		{
			my.ANIMATION += 5 * time_step;
			ent_animate(me,"putSWA",my.ANIMATION,NULL);
			if(my.ANIMATION > 100)
			{
			 ent_blend(my.STATE = 0,0,50);
			}
			
		}
		//the attack state
		if(my.STATE == 6)
		{
			my.ANIMATION += 4 * time_step;
			ent_animate(me,"attack",my.ANIMATION,NULL);
		}
		if(my.STATE == 7)
		{
	      jump_height = 75 * time_step;
	      jump_perct += 45 *time_step;
	     c_move(me,vector(0,0,jump_height),NULL,GLIDE);
			ent_animate(me,"jump",jump_perct,0);
			ent_blend("hang",0,25);
			
		}
		//press the key to change states
		//take out the sword if you are in the idle state
		//with the sword in sheath	
		if((key_t == 1)&& my.STATE == 0)
		{
			my.ANIMATION = 1;
			my.STATE = 2;		
		}
		//running and pull sword at the same time
		if((key_cuu == 1)&& (key_t ==1) && my.STATE == 1)
		{
			my.STATE = 2;
    	}
		
		//after changing states if you are trying to
		//move with the sword in hand
		if((key_cuu==1)&& my.STATE == 2)
		{
			my.ANIMATION = 1;
			my.STATE = 3;
		}
		//if you have stopped moving
		//play the idle with the sword in the hand 
		else if((key_cuu == 0)&& my.STATE == 3)
		{
			my.ANIMATION = 1;
			my.STATE = 4;
		}
		//run with the sword in hand
		if((my.STATE == 4) && key_cuu == 1)
		{
			my.ANIMATION = 1;
			my.STATE = 3;
		}
		//when your idle is sword in hand 
		//and you want to put it away
		if((key_p == 1) && my.STATE == 4)
		{
			my.ANIMATION = 1;
			my.STATE = 5;
			
		}
	//now you have put the sword away
	//go back to original state and start over again
	if((my.STATE == 5) && key_cuu == 1)
	{
			my.ANIMATION = 1;
			my.STATE = 1;
    }
   //Press the space key to make the player jump
	if(key_space == 1 && my.STATE == 0)
	{
		my.ANIMATION = 1;
       my.STATE = 7;
	}



Now I have some code that I got form the wiki about if the player is off the ground they should fall to the ground with gravity applied but it is real jerky when he falls down, plz help if you can.

Re: Please help. [Re: Tman] #310240
02/13/10 20:43
02/13/10 20:43
Joined: Feb 2009
Posts: 38
Germany
P
Phonech Offline
Newbie
Phonech  Offline
Newbie
P

Joined: Feb 2009
Posts: 38
Germany
you have var dist_down in your while loop getting initialized ever and ever again. take it out of your while loop and try it again. I'm not sure whether it solves the problem but you should give it a try...^^

Code:
var dist_down;
while(1)
{
...
}



Re: Please help. [Re: Phonech] #310398
02/14/10 17:11
02/14/10 17:11
Joined: Oct 2009
Posts: 60
T
Tman Offline OP
Junior Member
Tman  Offline OP
Junior Member
T

Joined: Oct 2009
Posts: 60
I never thought of that, kewl I will try that.

Re: Please help. [Re: Tman] #310883
02/17/10 14:37
02/17/10 14:37
Joined: Oct 2009
Posts: 60
T
Tman Offline OP
Junior Member
Tman  Offline OP
Junior Member
T

Joined: Oct 2009
Posts: 60
I think that I have my jump code and it works pretty good, just asking if you guys could take a look at it and let me know how I could make it better.
Code:
camera_follow(me);
	my.skill42 = floatv(25);

 		
 	VECTOR vFeet;
   vec_for_min(vFeet,me); // vFeet.z = distance from player origin to lowest vertex
 		
	my.STATE = 0;
	
	
	while(1)
	{

     
      
		// adjust entity to the ground height, using a downwards trace
		if(c_trace(my.x,vector(my.x,my.y,my.z-5000),IGNORE_ME | IGNORE_PASSABLE) > 0)
		dist_down= my.z + vFeet.z - target.z; // always place player's feet on the ground
		else
		dist_down = 0;	
		
	   if((dist_down > 0))
		{
		 ent_blend("jumpLS",0,75);	
		 dist_down = clamp(dist_down,0,accelerate(speed_down,10,0.1));
		
		}
		else
	    speed_down = 0;
	    
			//move the entity forward
			var distance =(key_cuu)* 25 *time_step;
			distance = sign(distance)* (abs(distance) + 0.5 * dist_down);
			c_move(me,vector(distance,0,0),vector(0,0,-dist_down),IGNORE_PASSABLE |GLIDE);
			
			
			//rotate player with the left and right keys
			my.pan += (key_cul-key_cur)*5* time_step;
			my.pan += (key_cud) * 5 * time_step;
		
      //default state
		if(my.STATE == 0)
		{
			my.ANIMATION += 2 *time_step;
		   ent_animate(me,"idleSWA",my.ANIMATION,ANM_CYCLE);
			
		}
		//the run state without the sword in hand
		if(my.STATE ==1)
		{
			

			ent_blend("runWS",25,45);
			//animate the player
			my.ANIMATION += 15 * time_step;
			ent_animate(me,"runWS",my.ANIMATION,ANM_CYCLE);
					
		}
		//pressing the move key to make him run with out the sword
		//changing his state
		if((key_cuu == 1)&& my.STATE == 0)
		{
			my.ANIMATION = 0;
			my.STATE = 1;
		}
		else if((!key_cuu)&& my.STATE == 1)
		{
			my.ANIMATION = 0;
			my.STATE = 0;
		}

	  //take the sword out and put it in the hand.
		if(my.STATE ==2)
		{
			my.ANIMATION += 5 *time_step;
			ent_animate(me,"takeSWO",my.ANIMATION,0);
			//blend the state from taking out the sword 
			//to the idle.
			if(my.ANIMATION > 100)
			{
			ent_blend(my.STATE = 4,0,50);
			}
				
		}
		//run with the sword in his hand
		if(my.STATE == 3)
		{
         
			ent_blend("run",25,45);
			//animate the player
			my.ANIMATION += 15 * time_step;
			ent_animate(me,"run",my.ANIMATION,ANM_CYCLE);
			
			
		
		}
		//idle with the sword in hand
		if(my.STATE == 4)
		{
		 
			my.ANIMATION += 2 *time_step;
		  ent_animate(me,"idleSWI",my.ANIMATION,ANM_CYCLE);
			
		}
		//putting the sword away
		if(my.STATE == 5)
		{
			my.ANIMATION += 5 * time_step;
			ent_animate(me,"putSWA",my.ANIMATION,NULL);
			if(my.ANIMATION > 100)
			{
			 ent_blend(my.STATE = 0,0,50);
			}
			
		}
		//the attack state
		if(my.STATE == 6)
		{
			my.ANIMATION += 4 * time_step;
			ent_animate(me,"attack",my.ANIMATION,NULL);
		}
		
		//press the key to change states
		//take out the sword if you are in the idle state
		//with the sword in sheath	
		if((key_t == 1)&& my.STATE == 0)
		{
			my.ANIMATION = 1;
			my.STATE = 2;		
		}
		//running and pull sword at the same time
		if((key_cuu == 1)&& (key_t ==1) && my.STATE == 1)
		{
			ent_blend(my.STATE = 2,25,50);
    	}
		
		//after changing states if you are trying to
		//move with the sword in hand
		if((key_cuu==1)&& my.STATE == 2)
		{
			my.ANIMATION = 1;
			my.STATE = 3;
		}
		//if you have stopped moving
		//play the idle with the sword in the hand 
		else if((key_cuu == 0)&& my.STATE == 3)
		{
			my.ANIMATION = 1;
			my.STATE = 4;
		}
		//run with the sword in hand
		if((my.STATE == 4) && key_cuu == 1)
		{
			my.ANIMATION = 1;
			my.STATE = 3;
		}
		//when your idle is sword in hand 
		//and you want to put it away
		if((key_p == 1) && my.STATE == 4)
		{
			my.ANIMATION = 1;
			my.STATE = 5;
			
		}
	//now you have put the sword away
	//go back to original state and start over again
	if((my.STATE == 5) && key_cuu == 1)
	{
		  
			my.ANIMATION = 1;
    		my.STATE = 1;
   }
   //Press the space key to make the player jump
	if(key_space == 1 && my.STATE == 1 && reached_height == 0)
	{
		 jump_height = minv(25,jump_height + 5 * time_step);
		 //jump_height = c_move(me,0, vector(0,0,jump_height ),GLIDE);
		 my.z = jump_height;
		 ent_animate(me,"jump",25,NULL);
		 ent_blend("hang",25,50);
		 if(jump_height == 25)
		 {
		 	ent_animate(me,"hang",my.ANIMATION,ANM_CYCLE);
		 	reached_height = 1;
		 	beep();
		 	jump_height = clamp(jump_height,0,accelerate(speed_down,10,0.1)); 
		 	ent_animate(me,"land",my.ANIMATION,0);	
		 }
		 else{
		 	speed_down = 0;
		 	ent_animate(me,"land",0,NULL);
		}
   } 
   if(key_space == 0 && my.STATE == 1 && reached_height == 1)
   {
   	reached_height = 0;
   }
   //Press the space key to make the player jump
	if(key_space == 1 && my.STATE == 3 && reached_height == 0)
	{
		 jump_height = minv(25,jump_height + 5 * time_step);
		 //jump_height = c_move(me,0, vector(0,0,jump_height ),GLIDE);
		 my.z = jump_height;
		 ent_animate(me,"jumpSIH",25,NULL);
		 ent_blend("jumpHS",25,50);
		 if(jump_height == 25)
		 {
		 	ent_animate(me,"jumpHS",my.ANIMATION,ANM_CYCLE);
		 	reached_height = 1;
		 	beep();
		 	jump_height = clamp(jump_height,0,accelerate(speed_down,10,0.1)); 
		 	ent_animate(me,"jumpLS",my.ANIMATION,0);	
		 }
		 else{
		 	speed_down = 0;
		 	ent_animate(me,"jumpLS",0,NULL);
		}
   } 
   if(key_space == 0 && my.STATE == 3 && reached_height == 1)
   {
   	reached_height = 0;
   }



Re: Please help. [Re: Tman] #311486
02/20/10 00:16
02/20/10 00:16
Joined: Oct 2009
Posts: 60
T
Tman Offline OP
Junior Member
Tman  Offline OP
Junior Member
T

Joined: Oct 2009
Posts: 60
I thought I had it but I was wrong again. Could someone show me a simple code example of how to use c_trace to do jump? I was using c_move but got some funky results, I tried to use my.z and it just jumps out of the world I may need to scale my model just a little bit bigger to make it work but I don't know, I only have been reading and studying this engine for 2 weeks and I have gotten this far thanks to the tuts but the don't go into jumping at all, so I am asking if you guys and gals could help.

Thanks.

Re: Please help. [Re: Tman] #311502
02/20/10 04:07
02/20/10 04:07
Joined: Oct 2009
Posts: 60
T
Tman Offline OP
Junior Member
Tman  Offline OP
Junior Member
T

Joined: Oct 2009
Posts: 60
If anyone could help and needs me to explain my code let me know because this portion of code is bugging me.

Re: Please help. [Re: Tman] #311550
02/20/10 15:02
02/20/10 15:02
Joined: Oct 2009
Posts: 60
T
Tman Offline OP
Junior Member
Tman  Offline OP
Junior Member
T

Joined: Oct 2009
Posts: 60
So no one know how to do this?

Re: Please help. [Re: Tman] #312161
02/23/10 14:57
02/23/10 14:57
Joined: Oct 2009
Posts: 60
T
Tman Offline OP
Junior Member
Tman  Offline OP
Junior Member
T

Joined: Oct 2009
Posts: 60
Thanks for everything guys I have things working so far will keep everyone updated the code is a lot cleaner so it is understandable and it will work with anyone's code. So when I get it done I will post so everyone could see it.


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