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
4 registered members (NewbieZorro, Grant, TipmyPip, AndrewAMD), 12,885 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
Page 1 of 2 1 2
Whats wrong with my gravity script? #271531
06/13/09 18:28
06/13/09 18:28
Joined: Mar 2006
Posts: 321
Norway
Eagelina Offline OP
Senior Member
Eagelina  Offline OP
Senior Member

Joined: Mar 2006
Posts: 321
Norway
Trying out a script that are supposed to make the player stay on the ground. But when I run it the player are up in the air, a coulpe of centimeters abow the floor. Why does it do that?
What is wrong with my gravity script.
Can anyone of you tell me that? In WED the player stands on the ground, but when I run the script the players are in the air......

GRAVITY code:
Code:
function gravity_player()
{
//////////////////gravity/////////////////////
// determine the ground distance by a downwards trace
//my.min_z *= 0.5;
var speed_down = 0;   // downward speed by gravity
   var anim_percent = 0; // animation percentage
   VECTOR vFeet;
   vec_for_min(vFeet,my); // vFeet.z = distance from player origin to lowest vertex
      
      var dist_down; 
//      if (c_trace(my.x,vector(my.x,my.y,my.z-5000),IGNORE_ME | IGNORE_PASSABLE | USE_BOX) > 0)
      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; // get distance between player's feet and the ground
      else
         dist_down = 0;

// apply gravity when the player is in the air
      if (dist_down > 0)  // above floor, fall down with increasing speed
         dist_down = clamp(dist_down,0,accelerate(speed_down,5,0.1));
      else                // on or below floor, set downward speed to zero
         speed_down = 0;

/////////////////////////////////////////////	
}


My Player code:
Code:
action trude_player()

{


      var mov_speed = 10; // movement speed
      var walk_prosent;//walk
      var stand_prosent;//stand

		var spacebar_clear = 1;//jump
		var z_adjust = 0;//jump

      VECTOR temp;
      VECTOR move_to_vector;//jump

		var jump_percentage; // animation percentage for jumping
      var distance_to_ground; // the distance between player's origin and the ground
      var jump_height;
      var reached_height;


///////////////
       player = my; // I'm the player	
			c_setminmax(my);
		//	my.z=1000;
		
       while (1)

       {

               ///////***STAND ******////////////
			//If the player arent moved with these keys, it is standing ... play stand animation
			     if(!key_w && !key_s && !key_cuu && !key_cud) 

             {

                       ent_animate(my, "stand", stand_prosent, ANM_CYCLE); // then play its "stand" animation

                       stand_prosent += 5 * time_step; // 5 = animation speed
                       gravity_player();

               }         
					////////////end stand//////////////////////////////////////////////

				 ////////////////Keys used to move player and play animation///////////////////  
				  
				 //Use key w to walk forward           
				if(key_w)
				{
					 ent_animate(my, "walk", walk_prosent, ANM_CYCLE); // then play its "walk" animation
				
				                       walk_prosent += 6 * time_step; // 6 = animation speed
				                       gravity_player();
				} 
				//Use key s to walk backwards
				if(key_s) 
				{
					 ent_animate(my, "walk", walk_prosent, ANM_CYCLE); // then play its "walk" animation
				
				                       walk_prosent += 6 * time_step; // 6 = animation speed
				                       gravity_player();
				}           
				 //Use key z turn left              
				if(key_d)
				{
					my.pan += 5  * time_step;
					gravity_player();
				}
				//Use key x turn right
				if(key_a)
				{
					my.pan -= 5  * time_step;
					gravity_player();
				}
				
				//use CursorUp to walk forward
				if(key_cuu)
				{
					ent_animate(my, "walk", walk_prosent, ANM_CYCLE); // then play its "walk" animation
				
				                       walk_prosent += 6 * time_step; // 6 = animation speed
				                       gravity_player();
				}
				//use CursorDown to walk backward
				if(key_cud)
				{
					ent_animate(my, "walk", walk_prosent, ANM_CYCLE); // then play its "walk" animation
				
				                       walk_prosent += 6 * time_step; // 6 = animation speed
				                       gravity_player();
				}
				
				//use CursorRight turn right
				if(key_cur)
				{
					my.pan -= 5  * time_step;
					gravity_player();
				}
				
				//use CursorLeft turn left
				if(key_cul)
				{
					my.pan += 5  * time_step;
					gravity_player();
				}
				
				 if(key_n)//start to scan...
				 {
				 	c_scan(my.x, my.pan, vector(360, 180, 200), IGNORE_ME); 
				}
				//use the mouse turn bouth ways
				player.pan -= 5 * mouse_force.x * time_step; 
				
				/////////////////end move keys////////////////////////////////////////


				
				////////////////////JUMP/////////////////////////////////



       VECTOR movement_speed[3]; // player's movement speed

       var anim_percentage; // animation percentage


              vec_set (temp.x, my.x); // copy player's position to temp

               temp.z -= 10000; // set temp.z 10000 quants below player's origin

               distance_to_ground = c_trace (my.x, temp.x, IGNORE_ME | USE_BOX);


               movement_speed.y = 0; // don't move sideways

               if (key_space && !reached_height)

               {

                       jump_height = minv(100, jump_height + 5 * time_step); // 40 sets the height, 5 sets the ascending speed

                       if (jump_height == 100) // reached the maximum height? Then start descending!

                       {

                               reached_height = 1;

                               jump_height = maxv(0, jump_height - 5 * time_step); // 5 sets the falling speed

                       }

               }

               else // space isn't pressed anymore?

               {

                       jump_height = maxv(0, jump_height - 3 * time_step); // use a smaller falling speed (3) for smaller jumps

                       if (!jump_height && !key_space) // the player has touched the ground?

                       {

                               reached_height = 0; // then allow it to jump again

                       }

               }

               movement_speed.z = -(distance_to_ground - 17) + jump_height; // 17 = experimental value

            movement_speed.z = maxv(-35 * time_step, movement_speed.z); // 35 = falling speed

               c_move (my, movement_speed.x, nullvector, GLIDE); // move the player

            if (!jump_height) // the player isn't jumping?

            {

//                   

                       anim_percentage += 5 * time_step; // 5 = animation speed

                       jump_percentage = 0; // always start jumping with the first frame

               }

            else // the player is jumping

            {

                    jump_percentage += 5 * time_step; // 5 = jump animation speed

                       ent_animate(my, "jump", jump_percentage, ANM_CYCLE); // play the "jump" animation

               }

 


					/////////////////////////SPEED////////////////////////////



					temp.x = mov_speed * (key_w - key_s + key_cuu - key_cud) * time_step;


               temp.y = mov_speed * (key_a - key_d) * 0.6 * time_step;
               temp.y = mov_speed * (key_cul-key_cur) * 0.6 * time_step;

               temp.z = 0;
               
               ////////////////////////end speed/////////////////////////

					//bind it al togehter so the player can use the movement in x direction//
               c_move (my, temp.x, nullvector, IGNORE_PASSABLE | GLIDE);
//                  c_move (my, nullvector, vector(0,0,-1000), IGNORE_PASSABLE | GLIDE);//forandret
                
               
              

               wait (1);

       }

}



A6 and A7 Commercial
-------------------
Programmer always searching for more to learn and understand. smile
Re: Whats wrong with my gravity script? [Re: Eagelina] #271574
06/13/09 23:52
06/13/09 23:52
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Before I look seriously into the code, try putting a single wait(1);
at the VERY start of your player action. Then let me know how it goes.

If this fixes it, the problem was that the c_setminmax was being run
BEFORE the end of the first frame since the entities creation.
Check the manual under c_setminmax as to why this is a problem.



"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Whats wrong with my gravity script? [Re: EvilSOB] #271609
06/14/09 07:54
06/14/09 07:54
Joined: Mar 2006
Posts: 321
Norway
Eagelina Offline OP
Senior Member
Eagelina  Offline OP
Senior Member

Joined: Mar 2006
Posts: 321
Norway
No, that didnt solve my problem. Still standing/walking a couple of centimeters above ground.

Here is a picture showing.... the chest is staying on the ground , but the player dont.


Last edited by Eagelina; 06/14/09 08:22.

A6 and A7 Commercial
-------------------
Programmer always searching for more to learn and understand. smile
Re: Whats wrong with my gravity script? [Re: Eagelina] #271612
06/14/09 08:35
06/14/09 08:35
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
It looks to be all in the "gravity_player" function to me.
I cant help that much cause I suck at c-script.

But I can tell you these two important things.

1> Your "accelerate(speed_down,5,0.1)" calculation wont work because speed_down is being
reset back to zero every time the function is called. That means EVERY frame.

2> Your gravity function tries to calculate a downward distance, but never actually uses it.
There is NO C_MOVE....

Hope this is of some help.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Whats wrong with my gravity script? [Re: EvilSOB] #271621
06/14/09 09:08
06/14/09 09:08
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Did you try to apply the player_gravity() to the player without any other function? That's the function that should determine the hieght of the player above the ground.

Re: Whats wrong with my gravity script? [Re: Pappenheimer] #271624
06/14/09 09:21
06/14/09 09:21
Joined: Mar 2006
Posts: 321
Norway
Eagelina Offline OP
Senior Member
Eagelina  Offline OP
Senior Member

Joined: Mar 2006
Posts: 321
Norway
I am not shure I understand you? I have applied the player_gravity() to every "key" movement in the player code. But it dont work.......


A6 and A7 Commercial
-------------------
Programmer always searching for more to learn and understand. smile
Re: Whats wrong with my gravity script? [Re: Eagelina] #271627
06/14/09 09:22
06/14/09 09:22
Joined: Mar 2006
Posts: 321
Norway
Eagelina Offline OP
Senior Member
Eagelina  Offline OP
Senior Member

Joined: Mar 2006
Posts: 321
Norway
Can anyone give me an "normal" example of an gravity script that does what it is supposed to. Make the player stays on the floor/ground al the time.

So I can try it and see if it is working here....

Thanks in advance.

Last edited by Eagelina; 06/14/09 09:25.

A6 and A7 Commercial
-------------------
Programmer always searching for more to learn and understand. smile
Re: Whats wrong with my gravity script? [Re: Eagelina] #271631
06/14/09 09:33
06/14/09 09:33
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Tobias Offline

Moderator
Tobias  Offline

Moderator

Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
The standard walking example in the manual under "c_move" uses gravity.

http://manual.3dgamestudio.net/ac_move.htm

I see you used a similar code, but the comment mentions that the player models center must be really inside the model, and not below its feet or something, and the player must not be smaller than his bounding box, maybe that was your problem? The blue bounding box in your screenie looks wrong (too big).



Re: Whats wrong with my gravity script? [Re: Tobias] #271647
06/14/09 10:18
06/14/09 10:18
Joined: Mar 2006
Posts: 321
Norway
Eagelina Offline OP
Senior Member
Eagelina  Offline OP
Senior Member

Joined: Mar 2006
Posts: 321
Norway
Yes this one works when I did add player = my; at the top of the code.

So I must study this code and compare it with mine. I just did use severals examples and combined them into my "own" code.

Thanks for the tips.


A6 and A7 Commercial
-------------------
Programmer always searching for more to learn and understand. smile
Re: Whats wrong with my gravity script? [Re: Tobias] #271649
06/14/09 10:22
06/14/09 10:22
Joined: Mar 2006
Posts: 321
Norway
Eagelina Offline OP
Senior Member
Eagelina  Offline OP
Senior Member

Joined: Mar 2006
Posts: 321
Norway
One litle question what the difference between

me and my ? Are they the same? I see that bouth are used in the online script.


A6 and A7 Commercial
-------------------
Programmer always searching for more to learn and understand. smile
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