2 registered members (NnamueN, 1 invisible),
1,489
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Gravity function for a player.
#416050
01/27/13 15:39
01/27/13 15:39
|
Joined: Jan 2013
Posts: 2
Mithun_Mohan
OP
Guest
|
OP
Guest
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
Expert
|
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á
wdakfenixx
Junior Member
|
Junior Member
Joined: Aug 2011
Posts: 58
Colombia/Bogotá
|
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: Mithun_Mohan]
#416685
02/03/13 15:20
02/03/13 15:20
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
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: Superku]
#416690
02/03/13 15:32
02/03/13 15:32
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
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: Superku]
#416695
02/03/13 15:55
02/03/13 15:55
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
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...
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|