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
how to detect slopes? #140693
07/12/07 12:21
07/12/07 12:21
Joined: Jul 2007
Posts: 24
N
noobie86 Offline OP
Newbie
noobie86  Offline OP
Newbie
N

Joined: Jul 2007
Posts: 24
HI all
i'm writing a code for simple vehicle movement without using physics (@xxxGuitar: I'm still using Newton for the other one, messing with the tire friction and getting better results now this is a different level) and i'm stuck at a point where i need to climb a slope..

I've made the car body to stop around 10 quants in the air so i can have space for the tires and also bcoz its the only way i could think of to detect slope using trace..
here's the Z movement code..

//Code start

if(!disable_trace)
{
//Z movement
vec_set(temp,my.x);
temp.z -= 4000;
trace_mode = ignore_me+ignore_sprites+IGNORE_MODELS;//+USE_BOX;
car_elevation = trace(my.x,temp);

if(car_elevation>70) {flag_bounce=1;}

if(car_elevation>25)
{ my.z-=fall_counter;
if(fall_counter<4) {fall_counter+=time;}
}//increase Z vel with time..


if(flag_bounce==1 && car_elevation<25)
{rebound_z(); fall_counter = 0; flag_bounce=0;}

if(car_elevation<25) {fall_counter = 0;}
}
//here rebound_z is a function that disables trace, 'bounces' the car and then enables trace again.

if(car_elevation<15) {my.z -= (car_elevation)*0.5*time;}
//climbing the slope.. 15 bcoz the trace value decreases when near a slope. The watch says 22 but it goes to 22 and below even on straight ground sometimes..

vec_to_angle(norm,normal.x); //detect floor normals
norm[0]-=180;
diffpan = my.pan - norm[0];

if((90-norm[1])>5) //on a slope
{
my.tilt = (90-norm[1])*cos(diffpan);
my.roll = (norm[1]-90)*sin(diffpan);
}


if((90-norm[1])<5) //on flat ground
{ if (my.tilt>0) {my.tilt-=4*time;}
if (my.tilt<0) {my.tilt+=4*time;}
my.roll = 0;
}

if(car_elevation<5) {my.z+=25;} //a bug in my code, not sure how to fix it, trace value suddenly drops while traveling on straight ground and i have to elevate the car to 10 quants again.

//Code end


When the car is on a slope, the tilt and roll is fine and goes according to the slope. The main problem is getting on the slope in the first place

Here are the problems
1. It stays at the base of the slope for a while before climbing it, if it climbs at all
2. Sometimes it doesn't climb after being stuck for a while.. at that time if i turn the car and face away from the slope, it shoots forward like a rocket! even though i didn't code for such a high velocity on normal running.
3. Sometimes it falls through the slope

If you've read until here, thanks a lot for ur patience and thanks in advance for any help.

Re: how to detect slopes? [Re: noobie86] #140694
07/17/07 01:09
07/17/07 01:09
Joined: Oct 2003
Posts: 827
22�21'24"N 114�07'30...
Frederick_Lim Offline
User
Frederick_Lim  Offline
User

Joined: Oct 2003
Posts: 827
22�21'24"N 114�07'30...
Maybe this thread can help.

The code from ventilator works great.

I made a small test level to test the script, you may find it here.

http://files.filefront.com/slopetest.zip/;8010117;/fileinfo.html

Hope this help.

Re: how to detect slopes? [Re: Frederick_Lim] #140695
07/18/07 10:35
07/18/07 10:35
Joined: Jul 2007
Posts: 50
N
Nomad Offline
Junior Member
Nomad  Offline
Junior Member
N

Joined: Jul 2007
Posts: 50
Fantastic demo Fredwrick_Lim, I use it as a foundation script now and Nemisis posted a version in Contributions for others to draw ideas from.
It will certainly be helpful to noobie86.


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