Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (SBGuy, dr_panther, Ayumi, Quad, AndrewAMD), 920 guests, and 1 spider.
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 enemy units #445811
09/25/14 20:13
09/25/14 20:13
Joined: Dec 2009
Posts: 82
D
Denn15 Offline OP
Junior Member
Denn15  Offline OP
Junior Member
D

Joined: Dec 2009
Posts: 82
i want to make enemy units in my game be affected by gravity, so that when they walk off a ledge they fall down. ive tried to use c_trace to check whether or not the ground is under the units which will increase a local variable that makes the units fall down to the ground faster and faster until they hit the ground where the value is set to 0.

the problem is that half the time they dont react at all after walking off a ledge and other times they slam into the ground and other times they fall down as they should but it is not consistent at all.

Code:
action enemy()
{
	var grav;
	while(my.health > 0)
	{
		if (c_trace(my.x, vector(my.x, my.y, my.z - 15), IGNORE_ME) == 0)
		{
                        grav = grav + 1 * time_step;
			c_move(me, nullvector, vector(0, 0, - grav * time_step), GLIDE);
		}
                if (c_trace(my.x, vector(my.x, my.y, my.z - 15), IGNORE_ME) != 0)
                {
                        grav = 0;
                }
		wait(1);
	}
	ent_remove(me);
}



have i done something completely wrong or is there a better method of doing it?

Re: gravity enemy units [Re: Denn15] #445812
09/25/14 21:22
09/25/14 21:22
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Have you had a look at the following article plus example code/ zip file: http://opserver.de/qwik8/index.php?title=Gravity ?


"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 enemy units [Re: Superku] #445825
09/26/14 12:18
09/26/14 12:18
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
by the way ,you are also multiplying by time_step twice there in your gravity code and movement code


Compulsive compiler
Re: gravity enemy units [Re: Wjbender] #445826
09/26/14 12:19
09/26/14 12:19
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Where?


"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 enemy units [Re: Superku] #445830
09/26/14 14:12
09/26/14 14:12
Joined: Dec 2009
Posts: 82
D
Denn15 Offline OP
Junior Member
Denn15  Offline OP
Junior Member
D

Joined: Dec 2009
Posts: 82
ive tried using the code you sent me for the enemy units and it works fine except for sometimes where some units fall faster than others.

I just dont understand why the code i made before wouldnt work. my code works on the player character but when if i use the same method for more than one unit of the same type it just doesnt work.

Re: gravity enemy units [Re: Denn15] #445838
09/26/14 20:17
09/26/14 20:17
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
You need to initialize local variables, grav could have any random value, maybe that is the cause for your problems.
Btw. I would not use the c_trace return value for ground detection but trace_hit or the hit struct (or the HIT_TARGET macro or whatever it is called). Calling c_trace two times in a row with the same parameters is pretty wasteful, too. Just use an else case instead.


"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 enemy units [Re: Superku] #445839
09/26/14 20:39
09/26/14 20:39
Joined: Dec 2009
Posts: 82
D
Denn15 Offline OP
Junior Member
Denn15  Offline OP
Junior Member
D

Joined: Dec 2009
Posts: 82
yea you are right. but grav should be a local variable which is why i dont understand it

Re: gravity enemy units [Re: Denn15] #445840
09/26/14 20:56
09/26/14 20:56
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
I think you misunderstood me. The content of grav as a local variable is preserved (/ restored) during and after each frame but its initial value could be any random value. Give the following example a try:

Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////

action enemy()
{
	var grav;
	printf("%.3f",(double)grav);
	wait(1);
	sys_exit("");
}

void main()
{
	level_load(NULL);
	ent_create(CUBE_MDL,nullvector,enemy);
}



The solution to this obviously is to write "var grav = 0;" instead.


"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 enemy units [Re: Superku] #445841
09/26/14 21:00
09/26/14 21:00
Joined: Dec 2009
Posts: 82
D
Denn15 Offline OP
Junior Member
Denn15  Offline OP
Junior Member
D

Joined: Dec 2009
Posts: 82
oh i see. grav seems to be 1040384.000

Last edited by Denn15; 09/26/14 21:18. Reason: i made a dumb question

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