1 registered members (TipmyPip),
18,466
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Jumping & stairs code required
#426590
07/25/13 13:51
07/25/13 13:51
|
Joined: Jul 2013
Posts: 66 Don't have a one...
DonaldThief
OP
Junior Member
|
OP
Junior Member
Joined: Jul 2013
Posts: 66
Don't have a one...
|
Hello, everyone I am using the usual gravity code from the AUM ,with some modification to make something like acceleration: I put the following in a while loop:
VECTOR temp, gravity_speed;
var distance_to_ground;
var max_gravity = -10*time_step;
vec_set(temp.x,my.x);
temp.z -= 5000;
distance_to_ground = c_trace(my.x,temp.x,IGNORE_ME | USE_BOX | IGNORE_PASSABLE);
gravity_speed.z = -(distance_to_ground - 17);
gravity_speed.z = clamp(gravity_speed.z,max_gravity,5);
max_gravity += -5*time_step;
max_gravity = clamp(max_gravity,-35*time_step,-10*time_step);
gravity_speed.x = 0;
gravity_speed.y = 0;
c_move(my,nullvector,gravity_speed.x,GLIDE | IGNORE_PASSABLE);
if(distance_to_ground <= 0.1) max_gravity = -10*time_step;
1) First, I want to increase the efficiency of the code and I mean the value 17 (in seventh line) ,how to set a proper value that suits the model (distance between the origin and feet) 'cause I tried that a lot using vec_for_min and stuff ,but it didn't work and the model moves upwards I added this before the code above:
vec_for_min(temp2.x,my);
leg_height = my.z - temp2.z;
then I replaced "17" with "leg_height" 1) I'd like to have a functional jumping code that suits the code above 2) There's a problem with this code which is going upstairs. How can I make it walk on the stairs instead of considering it as an obstacle? ThanQ for reading
Last edited by DonaldThief; 07/25/13 13:54. Reason: spelling
|
|
|
Re: Jumping & stairs code required
[Re: DonaldThief]
#426644
07/26/13 13:50
07/26/13 13:50
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Haha oh well. Did you read the article or only check the code?
vec_set(temp,vector(my.x,my.y,my.z-150+my.foot_height));
c_trace(my.x,temp,IGNORE_PASSABLE | IGNORE_ME | USE_BOX);
if(!trace_hit) vec_set(target,temp);
The temp vector obviously is set 2 lines before your questioned vec_set instruction. The idea is simple, we declare out trace target "temp", then we c_trace and should we not hit anything the target vector would be the nullvector, thus we overwrite it with our desired position (the content of temp). The reason for this is that we only want to have a vector somewhere below the player's feet, in fact we are normally only interested in the z-component of the target vector. Yes, target and hit.x are basically the same vector, using target, the normal vector and so on is just the old school way of doing it (which I prefer) because back then in the days there was no hit struct. vec_for_min is well explained in the manual, as pretty much every other lite-C instruction: http://www.conitec.net/beta/vec_for_min.htmEDIT: You have changed/ deleted your old post, so my answer may seem somehow off to other users.
Last edited by Superku; 07/26/13 13:50.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: Jumping & stairs code required
[Re: DonaldThief]
#426646
07/26/13 13:57
07/26/13 13:57
|
Joined: Jul 2013
Posts: 66 Don't have a one...
DonaldThief
OP
Junior Member
|
OP
Junior Member
Joined: Jul 2013
Posts: 66
Don't have a one...
|
Sorry, but I find this code difficult to understand. And the stuff in the web page is different from the downloadable code...... BTW, if my.z > my.soil_height ,why do we set my.speed_z to zero? We have to perform a vertical motion EDIT: Haha oh well. Did you read the article or only check the code? I didn't understand both 
vec_set(temp,vector(my.x,my.y,my.z-150+my.foot_height));
c_trace(my.x,temp,IGNORE_PASSABLE | IGNORE_ME | USE_BOX);
if(!trace_hit) vec_set(target,temp);
The temp vector obviously is set 2 lines before your questioned vec_set instruction. The idea is simple, we declare out trace target "temp", then we c_trace and should we not hit anything the target vector would be the nullvector, thus we overwrite it with our desired position (the content of temp). The reason for this is that we only want to have a vector somewhere below the player's feet, in fact we are normally only interested in the z-component of the target vector. This was the only thing in the code that I understood. And it was a mistake to post my previous post that I deleted as I was confused about the "target" vector (I didn't know what it is as I'm a B-E-G-I-N-N-E-R) I know it is well-explained but I just want to be more sure
EDIT: You have changed/ deleted your old post, so my answer may seem somehow off to other users.
OK. I DELETED it as ,at that particular point, I realised what is "target".
Last edited by DonaldThief; 07/26/13 14:11.
|
|
|
Re: Jumping & stairs code required
[Re: Superku]
#426708
07/27/13 14:17
07/27/13 14:17
|
Joined: Jul 2013
Posts: 66 Don't have a one...
DonaldThief
OP
Junior Member
|
OP
Junior Member
Joined: Jul 2013
Posts: 66
Don't have a one...
|
@Superku your gravity is pretty good and works perfectly in your sample project ,but it doesn't fit the rest of my player's action as I use some dumb way for animating, moving...etc. and I got some problems with animation ,not because of your code ,but because of my player's code and the player's feet kept sinking into the ground So what did I do? I modified your code and made it more simple (at least for me) ,but I've got less problems  as I no longer have an animation problem (actually the animation works perfectly) ,but I still have the sinking-feet problem  Here's my code inspired from yours:
gravity_speed.x = 0;
gravity_speed.y = 0;
vec_for_min(feet_height.x,my);
feet_height.z *= my.scale_z;
vec_set(temp.x,my.x);
temp.z -= 5000;
c_ignore(8,0);
distance_to_ground = c_trace(my.x,temp.x,IGNORE_ME | USE_BOX | IGNORE_PASSABLE) - abs(feet_height.z);
DEBUG_VAR(distance_to_ground,100); //It is clear that it is negative!
if(distance_to_ground > 0)
{
gravity_speed.z -= 9*time_step;
if(gravity_speed.z < -90) gravity_speed.z = -90;
}
else
{
jumping = 0; //"jumping" is for animation
gravity_speed.z = 0;
if(key_space)
{
if(key_space_off)
{
key_space_off = 0;
gravity_speed.z = 65*time_step;
jumping = 1;
}
}
else
{
key_space_off = 1;
}
}
c_move(my,nullvector,gravity_speed.x,GLIDE | IGNORE_PASSABLE);
Bugs:- * There's only one bug. The feet of the player (from the "templates" folder) sometimes sink into the ground and sometimes not. Also, I think the reason for this is that "distance_to_ground" is negative after putting a "DEBUG_VAR" instruction Thank you for always introducing help when needed Best wishes
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|