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
1 registered members (TipmyPip), 18,449 guests, and 6 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
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...
D
DonaldThief Offline OP
Junior Member
DonaldThief  Offline OP
Junior Member
D

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:

Code:
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:

Code:
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] #426613
07/25/13 21:04
07/25/13 21:04
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Have you seen the following article and code already: http://opserver.de/mwik4/index.php?title=Gravity ?

I don't think I've tested it with stairs but it could work already.


"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: Superku] #426642
07/26/13 13:45
07/26/13 13:45
Joined: Jul 2013
Posts: 66
Don't have a one...
D
DonaldThief Offline OP
Junior Member
DonaldThief  Offline OP
Junior Member
D

Joined: Jul 2013
Posts: 66
Don't have a one...
But how does vec_for_min work? Is it relative to entity origin or world origin? (if the minimum vertex is below the entity's origin by 10 quants, will vec_for_min vector.z = (-10) or (entity position-10)?) 'cause I can't figure out what foot_height skill represents.

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 Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Haha oh well. Did you read the article or only check the code?

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.htm

EDIT: 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...
D
DonaldThief Offline OP
Junior Member
DonaldThief  Offline OP
Junior Member
D

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:

Originally Posted By: Superku
Haha oh well. Did you read the article or only check the code?


I didn't understand both confused


Originally Posted By: Superku

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.


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)



Originally Posted By: Superku

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.htm



I know it is well-explained but I just want to be more sure


Originally Posted By: Superku


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: DonaldThief] #426647
07/26/13 14:02
07/26/13 14:02
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
The stuff in the wiki article is not different to the downloadable code.

We don't set it to 0, only in the other case.


"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: Superku] #426650
07/26/13 14:17
07/26/13 14:17
Joined: Jul 2013
Posts: 66
Don't have a one...
D
DonaldThief Offline OP
Junior Member
DonaldThief  Offline OP
Junior Member
D

Joined: Jul 2013
Posts: 66
Don't have a one...

Re: Jumping & stairs code required [Re: DonaldThief] #426654
07/26/13 14:33
07/26/13 14:33
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Oh, I see, that's just a typo and it's fixed now. However, you could have guessed that from the following code (and/ or text).


"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: Superku] #426708
07/27/13 14:17
07/27/13 14:17
Joined: Jul 2013
Posts: 66
Don't have a one...
D
DonaldThief Offline OP
Junior Member
DonaldThief  Offline OP
Junior Member
D

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 smile as I no longer have an animation problem (actually the animation works perfectly) ,but I still have the sinking-feet problem frown


Here's my code inspired from yours:

Code:
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

Re: Jumping & stairs code required [Re: DonaldThief] #426709
07/27/13 15:41
07/27/13 15:41
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
Why not just use a min/max function?

Page 1 of 2 1 2

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