Gravity

Posted By: Bennett

Gravity - 06/08/11 19:49

Can someone please explain me how to use simple gravity?
I am using this code for jumping, and I suppose setting a downwards speed somehow might complete it.

if(key_space)
{
c_move(my, vector(0 ,0,15*time_step), nullvector,GLIDE);

}
Posted By: JakeBilbe

Re: Gravity - 06/08/11 21:26

Code:
if(key_space)
{
c_move(my, vector(0 ,0,15*time_step), nullvector,GLIDE);
else
c_move(my, vector(0,0,-15*time_step), nullvector,GLIDE;
}


something like that maybe?
Posted By: 3run

Re: Gravity - 06/09/11 15:04

Look at the last AUM! There is a gravity example!
Posted By: Bennett

Re: Gravity - 06/09/11 16:12

thanks...

Hey, you're a freerunner? I'm a Traceur! what a coincidence
Posted By: 3run

Re: Gravity - 06/09/11 16:17

Yeah I am, nice to see colleague here laugh BTW not Traceur but Tracer.
Posted By: Bennett

Re: Gravity - 06/09/11 16:19

sry, it's because I speak french too...
it's a habit
Posted By: Bennett

Re: Gravity - 06/09/11 16:41

can someone please look for n00b mistakes like curly brackets? I didn't find anything, but Acknex crashes when I run this...

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

#define STATE     skill1
#define ANIMATION skill2
function main()
{
	level_load("Puschel.wmb"); 	
}

function camera_follow(ENTITY* ent)
{
	while(1) 
	{
		vec_set(camera.x,vector(-400,0,300));  // camera position relative to the player      
		vec_rotate(camera.x,ent.pan); // rotate the camera position with the player
		vec_add(camera.x,ent.x);      // add player position
		vec_set(camera.pan,vector(ent.pan,-20,0)); // look in player direction, slighty down      
		wait(1);
	}
}

action puschel()
{
	camera_follow(me);
	
	var speed_down = 0;   // downward speed by gravity
	VECTOR vFeet;
	vec_for_min(vFeet,me); // vFeet.z = distance from player origin to lowest vertex
	my.STATE = 1;
	
	while (1)
	{
	
// state 1: walking ////////////////////////////////////////////
		if (my.STATE == 1)
		{
				if(key_space)
		{
			c_move(my, vector(0 ,0,15*time_step), nullvector,GLIDE); //jump upwards
			
			}
		}
		}
		
// determine the ground distance by a downwards trace
      var dist_down; 
      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; // 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;
// rotate the entity with the arrow keys     
			my.pan += (key_cul-key_cur)*8*time_step;   

// move the entity forward/backward with the arrow keys
			var distance = (key_cuu-key_cud)*8*time_step;
			c_move(me, vector(distance,0,0), nullvector,GLIDE);
					
						wait(1);
				}
			}
	}


Posted By: 3run

Re: Gravity - 06/09/11 16:44

Here:

Code:
if (my.STATE == 1)
{
if(key_space)
{
c_move(my, vector(0 ,0,15*time_step), nullvector,GLIDE); //jump upwards

}
}
}

Organize your script better... that way it will be more easy to find mistakes.
Posted By: Pappenheimer

Re: Gravity - 06/09/11 17:07

You have to organize your brackets and tabs properly, then you find it easely, if there's something wrong.
Posted By: Bennett

Re: Gravity - 06/09/11 17:47

Whats the mistake there? I don't see it
Posted By: Pappenheimer

Re: Gravity - 06/09/11 17:55

The closing bracket has to be always at the same tab as the opening bracket.
Second: if you place the cursor in SED right behind an opening bracket, this bracket will be shown bold and its corresponding closing bracket as well. This way you can assure that each opening bracket has its unique and right positioned closing bracket.
Posted By: Bennett

Re: Gravity - 06/09/11 17:55

ah... I found it, thank you!
Posted By: Bennett

Re: Gravity - 06/09/11 17:59

Übrigens vor deinem Post gefunden... ;D
Posted By: Bennett

Re: Gravity - 06/09/11 18:26

Why do I get a syntax error for the second c_move?

Code:
if(key_space)
				{
					c_move(my, vector(0 ,0,15*time_step), nullvector,GLIDE); //jump upwards
				}
			else
				{
					c_move(my, vector(0 ,0,-15*time_step), nullvector,GLIDE; //fall
				}


Posted By: Bennett

Re: Gravity - 06/09/11 18:29

The forum doesn't align like the editor...
Posted By: Bennett

Re: Gravity - 06/09/11 18:31

okay, i'm stupid... I forgot a bracket grin
Posted By: JakeBilbe

Re: Gravity - 06/09/11 22:49

Wow you guys do parkour too tongue Bennett I am just starting out on Lite-C to PM me on here if you want and you can add me on MSN or something Id be glad to help out or whatever.
© 2024 lite-C Forums