Gamestudio Links
Zorro Links
Newest Posts
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
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (NnamueN, 1 invisible), 1,489 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Gravity function for a player. #416050
01/27/13 15:39
01/27/13 15:39
Joined: Jan 2013
Posts: 2
M
Mithun_Mohan Offline OP
Guest
Mithun_Mohan  Offline OP
Guest
M

Joined: Jan 2013
Posts: 2
I have been trying a gravity function for a player using c_move and the script from the workshop 24. But i did not have any success. Can some one help me ?(I dont want any physics related options for now.)

int height;
action func_player()
{
//set(my,INVISIBLE);
int x_speed;
VECTOR vfeet;
int angle , fall;
vec_for_min(vfeet,me);

while(1)
{

x_speed = 3 ;
fall -= 2;
c_move(my,vector(x_speed * time_step * (key_cuu - key_cud),0,0.5*sin(angle) * (key_cuu - key_cud)*time_step +(0.5*sin(angle)*key_shift * time_step)),nullvector,GLIDE);
camera.x = my.x;
camera.y = my.y;
camera.z = my.z;

camera.pan = my.pan ;
my.pan += (key_cul - key_cur) * 8 * time_step;
c_trace(my.x,vector(my.x,my.y,my.z - 1000),IGNORE_PASSABLE | IGNORE_ME);
if(my.z >= (hit.z - vfeet.z))
{

c_move(me,vector(0,0, fall * time_step),nullvector,GLIDE);
}
else
{
my.z = hit.z - vfeet.z;


}
angle += 10;
wait(1);
}
}

My idea is not really good as c_move puts the player down but the my.z line puts the player up.



Last edited by Mithun_Mohan; 01/27/13 15:52.
Re: Gravity function for a player. [Re: Mithun_Mohan] #416051
01/27/13 15:41
01/27/13 15:41
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Please post you code so that we can have a look at it.


Always learn from history, to be sure you make the same mistakes again...
Re: Gravity function for a player. [Re: Uhrwerk] #416073
01/27/13 21:10
01/27/13 21:10
Joined: Aug 2011
Posts: 58
Colombia/Bogotá
W
wdakfenixx Offline
Junior Member
wdakfenixx  Offline
Junior Member
W

Joined: Aug 2011
Posts: 58
Colombia/Bogotá
Code:
function Entity_gravity(var Dist2floor, var fallspeed, var resilience, ENTITY* ent)
{
 VECTOR temp;
 var range=0.2;//play with this
 var current_height;
 vec_set(temp.x, ent.x);
 temp.z -= 10000;
 current_height = c_trace(ent.x, temp.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX | GLIDE | IGNORE_PASSENTS);
 
 if(current_height > Dist2floor+range)
 {ent.z -= fallspeed * time_step;}

 if(current_height < Dist2floor-range)
 {ent.z += resilience*time_step;}
 return current_height;
}



This is and old function that ive made a long time ago, but i think it is what you´re looking for
You just have to call it inside a loop from the entity´s action

Last edited by wdakfenixx; 01/27/13 21:21. Reason: Forgot to tell you how to use it

CAUTION :The content above could blow your mind
Re: Gravity function for a player. [Re: wdakfenixx] #416669
02/03/13 10:12
02/03/13 10:12
Joined: Jan 2013
Posts: 2
M
Mithun_Mohan Offline OP
Guest
Mithun_Mohan  Offline OP
Guest
M

Joined: Jan 2013
Posts: 2
Thanks for the code. laugh

Re: Gravity function for a player. [Re: Mithun_Mohan] #416685
02/03/13 15:20
02/03/13 15:20
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Here is a general remark. When you move a character you should either use c_rotate and move OR set the models coordinates and angle directly. But never do both of these methods at the same time. As soon as you set any value directly you loose collision control and hence any prior call to c_move and c_rotate renders pointless.


Always learn from history, to be sure you make the same mistakes again...
Re: Gravity function for a player. [Re: Uhrwerk] #416688
02/03/13 15:29
02/03/13 15:29
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Using c_move without c_rotate is perfectly fine, even changing the position manually in combination with c_move is okay too.


"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: Gravity function for a player. [Re: Superku] #416690
02/03/13 15:32
02/03/13 15:32
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Any direct change of a coordinate bears the risk of moving the entity into something solid. The same is true for c_rotate. How is that ok?

There are of course exceptions where the player is cone-like or where there is never something above the player because of the game mechanics so you can always move him up.


Always learn from history, to be sure you make the same mistakes again...
Re: Gravity function for a player. [Re: Uhrwerk] #416694
02/03/13 15:47
02/03/13 15:47
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
As you may know that 90% of the time I'm coding movement or similar related stuff and I simply never use c_rotate, it's just unhelpful and bad for the gameplay (except for maybe a door where it could be useful).
In fact you should not use c_move all the time but only when it is necessary, f.i. get the distance to the ground with c_trace and USE_BOX and set the z-position of the entity manually when it is close to the ground (the bounding box should hover above the ground). c_move does not help here, instead it may prevent that the player's/ entity's feet get pulled out of the ground.
As a general rule I think all actors should have an xy-symmetrical bbox and change my.pan manually.


"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: Gravity function for a player. [Re: Superku] #416695
02/03/13 15:55
02/03/13 15:55
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
I don't need to tell you that you arguments are all perfectly valid and a good advice for advanced programmers. But please be aware that your expertise concerning movement methods is really extraordinary.

I still think that a consistent use of c_move and c_rotate is a good advice for beginners. The direct change of the pan value is even suited for beginners though.


Always learn from history, to be sure you make the same mistakes again...

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