Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 947 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Gravity and A7... #209269
06/02/08 09:11
06/02/08 09:11
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline OP
Expert
Helghast  Offline 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:
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:
Code:
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


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: Gravity and A7... [Re: Helghast] #209274
06/02/08 09:34
06/02/08 09:34
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

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:

Code:
// 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 Offline OP
Expert
Helghast  Offline OP
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
awh! you are the man!! this works exactly as intended laugh

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,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: Gravity and A7... [Re: Helghast] #211998
06/19/08 15:37
06/19/08 15:37
Joined: Apr 2006
Posts: 28
LB, CA, USA
WINBERRY Offline
Newbie
WINBERRY  Offline
Newbie

Joined: Apr 2006
Posts: 28
LB, CA, USA
Spirit,
Thanks for the code!

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 Offline
Member
NL_3DGS_n00b  Offline
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:

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

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

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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