Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 718 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
jump script with real gravity, maybe... #112376
02/16/07 21:24
02/16/07 21:24
Joined: May 2006
Posts: 90
England
TigerTao Offline OP
Junior Member
TigerTao  Offline OP
Junior Member

Joined: May 2006
Posts: 90
England
Not sure where to put this but...

Ive been looking for a decent jump script but, like many, not found one that really looks right so I decided to make a script that deals only with gravity and then make a player jump with just his initial velocity which is then acted upon by gravity.

It works well enough and was hoping others can test to see how it works for them as there are still problems with it such as when gravity kicks in it can suck the player to the ground. Also the initial velocity of jumping seems a bit slow for me and the character sinks into the ground a bit and then pops back up when at rest.


Anyway here it is, based on Lancaster's KH movement code

//place variables in your variable list

var gravity = -0.1; //higher the value, the stronger gravity works
var time_count = 0;

//place code below in player action code

move_result = c_trace(vector(my.x,my.y,my.z - my.z_offset), vector(my.x,my.y,my.z - 4000),use_aabb | ignore_passable | glide); //find distance of ground to player

IF (move_result < 1) //am I in ground? push me back up
{
my.move_z = -1 * move_result;
time_count = 0;

IF (key_space == 0 && space_press == 1 ) { space_press = 0; }
IF (key_space == 1 && space_press == 0 )
{
space_press = 1;
my.velocity_z = 3 * time; //higher the velocity the bigger the jump
}
}
IF (key_space == 0 && space_press == 0 ) {my.velocity_z = 0;}

time_count += time; //store amount of time whilst in air
my.move_z =(my.velocity_z * time_count) + ((gravity * pow(time_count,2))/2); //gravity equation

my.move_x = current_speed * time; //horizontal movement

c_move(my,my.move_x,nullvector, use_aabb | ignore_passable | glide);

Thats it, let me know how it works for you.

*edit* changed velocity to a lower value

Last edited by TigerTao; 02/16/07 21:35.
Re: jump script with real gravity, maybe... [Re: TigerTao] #112377
02/16/07 21:44
02/16/07 21:44
Joined: Oct 2005
Posts: 196
ambe Offline
Member
ambe  Offline
Member

Joined: Oct 2005
Posts: 196
is it still full air control?


- code monkey
Re: jump script with real gravity, maybe... [Re: ambe] #112378
02/16/07 21:49
02/16/07 21:49
Joined: May 2006
Posts: 90
England
TigerTao Offline OP
Junior Member
TigerTao  Offline OP
Junior Member

Joined: May 2006
Posts: 90
England
This script only deals with pushing you back to the ground after jumping or falling so ignores any change in direction of movement for the time being. If that is what you mean?

Last edited by TigerTao; 02/16/07 21:58.
Re: jump script with real gravity, maybe... [Re: TigerTao] #112379
02/17/07 22:30
02/17/07 22:30
Joined: Nov 2004
Posts: 862
Australia
DavidLancaster Offline
User
DavidLancaster  Offline
User

Joined: Nov 2004
Posts: 862
Australia
Check out the Kingdom Hearts movement tutorial, it may not be the most 'realistic' gravity you're looking for but it does have a solution for sinking into the ground/bobbing.

Re: jump script with real gravity, maybe... [Re: DavidLancaster] #112380
02/18/07 22:55
02/18/07 22:55
Joined: Nov 2004
Posts: 862
Australia
DavidLancaster Offline
User
DavidLancaster  Offline
User

Joined: Nov 2004
Posts: 862
Australia
Sorry I hope I'm not 'stealing' your thread

I'm sure your gravity works more realistically than this but this is a general function I use:

//using z_dist, gravity etc as skill defines, this function returns my.move_z which you can then use in a c_move instruction

Code:

FUNCTION handle_gravity() {
result = c_trace(my.x,vector(my.x,my.y,my.z - 4000),use_polygon|use_box|ignore_me|ignore_passable); //you may use a different trace_mode
my.z_dist = result - 3; // placing the entity a little above ground to stop c_move ellipoid hull collision with ground
IF (my.z_dist < 3) {
my.force_z = -1 * my.z_dist;
} ELSE {
my.force_z -= my.gravity * time; //how fast we accelerate
my.force_z = max(-60,my.force_z); //maximum velocity
}
my.velocity_z += (time_step * my.force_z) - (min(time_step*0.7,1) * my.velocity_z);
my.move_z = my.velocity_z * time_step;
IF (my.z_dist < 0) { my.move_z = -my.z_dist; } //if we are below the ground place entity above ground
}




Moderated by  adoado, checkbutton, mk_1, Perro 

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