4 registered members (ozgur, Ayumi, VHX, monarch),
1,161
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Gravity and A7...
#209269
06/02/08 09:11
06/02/08 09:11
|
Joined: Jan 2004
Posts: 3,023 The Netherlands
Helghast
OP
Expert
|
OP
Expert
Joined: Jan 2004
Posts: 3,023
The Netherlands
|
Ok, so i have been working a lot lately on creating an RPG template code... all aspects work good, except gravity... I had implemented kingdom hearts tutorial, and that worked, to some extent. What happened that when running up hills (my levels are made from models with polygon collision) at low FPS, he wouldnt climb the hill at all, and just stand at the bottom of it doing nothing. So i decided i would simply use single point collision and snap the player to that target.z value (as i have done forever in A6 and proved working!) great, so i take this (A6) code:
function set_gravity
{
var target_trace[3]; // variable for temp storage of the trace
vec_set(target_trace, my.x);
target_trace.z -= 5000;
trace_mode = ignore_me + ignore_sprites + ignore_models + use_box + ignore_passable;
my.z = -trace(my.x, target_trace);
}
and convert that to A7:
function handle_gravity() {// pulls objects to the ground ;) *hence the name "gravity":P*
VECTOR target_trace; // variable for temp storage of the trace
vec_set(target_trace, my.x);
target_trace.z -= 5000;
result = c_trace(my.x, target_trace, IGNORE_ME | IGNORE_PASSABLE | USE_BOX | USE_POLYGON);
vec_set(my.z, target.z);
my.z += 25;
}
Guess what... it doesnt work, at all! can anyone here share a code that does work with single point "gravity" ? I'm really desperate for this! thanks in advance, Dennis
|
|
|
Re: Gravity and A7...
[Re: Helghast]
#209274
06/02/08 09:34
06/02/08 09:34
|
Joined: Sep 2003
Posts: 929
Spirit
Moderator
|
Moderator
Joined: Sep 2003
Posts: 929
|
Well I would say neither of those codes could have worked. In the A6 code youre setting the z position to the result of a trace, this does not make sense to me unless by some chance the floor is exactly at 0 position. The A7 code will even crash, youre using vec_set with a z value, this will write past the target vector and trash the memory. You probably meant to change the z value only but can not use vec_set then. For gravity theres no difference between A6 and A7 so you can use the same function. This is from the online manual: // determine the ground distance by a downwards trace
var dist_to_ground;
VECTOR vFeet;
vec_for_min(vFeet,me); // vFeet.z = distance between player origin and lowest player vertex
result = c_trace(my.x, vector(my.x,my.y,my.z-5000),IGNORE_ME | IGNORE_PASSABLE | USE_BOX);
if (result > 0)
dist_to_ground = my.z + vFeet.z - target.z; // the distance between player's feet and the ground
else
dist_to_ground = 0; and then: m.z -= dist_to_ground; or: my.z = target.z - vFeet.z; (dont need dist_to_ground in that case) I hope this helps.
|
|
|
Re: Gravity and A7...
[Re: Spirit]
#209286
06/02/08 11:07
06/02/08 11:07
|
Joined: Jan 2004
Posts: 3,023 The Netherlands
Helghast
OP
Expert
|
OP
Expert
Joined: Jan 2004
Posts: 3,023
The Netherlands
|
awh! you are the man!! this works exactly as intended and yeah, i've never been too good at writing gravity codes... I never actually had any more problems with something else come to think of it XD anyway, thanks! however, where did you find this in the manual ? i looked, but couldnt find it (local manual though...). kind regards and thanks for the help,
|
|
|
Re: Gravity and A7...
[Re: WINBERRY]
#212028
06/19/08 19:11
06/19/08 19:11
|
Joined: Jul 2005
Posts: 262 Earth, The Netherlands
NL_3DGS_n00b
Member
|
Member
Joined: Jul 2005
Posts: 262
Earth, The Netherlands
|
This code works very nice, I was looking for it too. I have a question regarding to this code. How can I make the player jump. (By space key for example) Right now I have this in my player action: VECTOR vFeet;
var dist_to_ground;
vec_for_min(vFeet,me); And this above in in the WHILE loop which the player movement is in. result = c_trace(my.x, vector(my.x,my.y,my.z-5000),IGNORE_ME | IGNORE_PASSABLE | USE_BOX);
if (result > 0)
dist_to_ground = my.z + vFeet.z - target.z;
else
dist_to_ground = 0; So how can I make this work with jumping?
Last edited by NL_3DGS_n00b; 06/19/08 19:13.
The best games are the games you create yourself.
|
|
|
|