|
gravity enemy units
#445811
09/25/14 20:13
09/25/14 20:13
|
Joined: Dec 2009
Posts: 82
Denn15
OP
Junior Member
|
OP
Junior Member
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.
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: Superku]
#445825
09/26/14 12:18
09/26/14 12:18
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
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: Denn15]
#445840
09/26/14 20:56
09/26/14 20:56
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
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:
///////////////////////////////
#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
Denn15
OP
Junior Member
|
OP
Junior Member
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
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|