2 registered members (AndrewAMD, 1 invisible),
863
guests, and 8
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Falling Damage
#456940
12/16/15 11:27
12/16/15 11:27
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
OP
User
Joined: Jun 2010
Posts: 590
California
|
I am trying to make it so that if the player falls vertically a certain distance, the player will take damage to its health. So far, this is the code that causes the player to fall with gravity:
action player_code()
{
...
dtimer();
if(c_trace(my.x, vector(my.x, my.y, my.z - my.FEET_HEIGHT),
IGNORE_ME | IGNORE_PASSABLE | IGNORE_PASSENTS |
USE_POLYGON))
{
time_elapsed = dtimer();
my.z = target.z + (my.FEET_HEIGHT);
DEBUG_VAR(my.z, 150);
DEBUG_VAR(time_elapsed, 200);
gravity_var = 0;
jumplck = 0;
if(time_elapsed >= 20)
{
beep();
}
}
...
}
I am assuming that I would use the dtimer() function somehow, in that if the player falls within a certain amount of time, the player will take a certain amount of damage? Right now, I am trying to get the program to beep() while the player is falling in mid-air, and run the dtimer() during that period of falling. No beeping is occurring while the player falls in mid-air, with the above code. Does anyone know how I can measure how long the player falls? I notice that the time_elapsed and my.z values using the DEBUG_VAR() function above disappear to nothing (no value visible) while the player falls in mid-air. These values only show up when the player is walking on the ground without falling. Does anyone have an idea on how to make the player take damage while falling? I am trying different methods, but none seem to be working. Any help would be appreciated. Thank you.
Last edited by Ruben; 12/16/15 18:30.
|
|
|
Re: Falling Damage
[Re: Dico]
#456957
12/17/15 04:36
12/17/15 04:36
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
OP
User
Joined: Jun 2010
Posts: 590
California
|
But I wonder how I would take a point before, and another point after falling, and compare the two. In other words, I am trying to figure out where in the code the actual falling takes place. Even when I put this code in the program:
action player_code()
{
...
DEBUG_VAR(my.z, 150);
...
if(my.z == NULL)
{
beep();
}
...
}
...the game does not beep when the player drops off a cliff in mid-air, even though my.z does not give off any value through the DEBUG_VAR() function while the player is falling. my.z does show a value through DEBUG_VAR() when the player is touching the ground.
Last edited by Ruben; 12/17/15 04:38.
|
|
|
Re: Falling Damage
[Re: Ruben]
#456958
12/17/15 05:00
12/17/15 05:00
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
OP
User
Joined: Jun 2010
Posts: 590
California
|
Even if I change the code to: or or
if(my.z == 0)
{
beep();
}
or
if(my.z == NULL)
{
beep();
}
...no beeping is taking place while the player is not touching the ground, while jumping or falling off a ledge. For the: The game beeps when the player is touching the ground, but does not beep when the player jumps, or falls off a ledge. In other words, every time the player is not touching the ground, no beeping takes place.
Last edited by Ruben; 12/17/15 05:01.
|
|
|
Re: Falling Damage
[Re: Ruben]
#456960
12/17/15 05:44
12/17/15 05:44
|
Malice
Unregistered
|
Malice
Unregistered
|
^ both post LMFAO!!!! the player my.z is it's z location in the world.
var z_before =0;
var z_after =0;
var fall=0;
while()....
{
if()....
z_before=my.z;
.... fall
if(my.falling !=true)
z_after=my.z;
fall=vec_dist(vector(0,0,z_before),vector(0,0,z_after));
}
my.z ==0 only when your player is at world (x,x,0) Who's code did you hijack and hack up? Really man, you don't know where in your code, you wrote the part that does the falling? Thanks for the laughs Mal
Last edited by Malice; 12/17/15 05:47.
|
|
|
Re: Falling Damage
[Re: ]
#456961
12/17/15 06:19
12/17/15 06:19
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
OP
User
Joined: Jun 2010
Posts: 590
California
|
Okay, I see your point about my.z = 0. But what about my.z = NULL?
When the player stands on a ledge, my.z = 2333.827 . When the player walks off the ledge, and the player is falling in mid-air, the value of my.z disappears to nothing, as in no value visible. I would think that the my.z would still remain visible, and show it counting down rapidly, but it does not.
When the player lands on the ground, a value for my.z suddenly appears as 49.267. Yes, I would like to take 2333.827 - 49.267 = 2284.56, and judging by 2284.56, give the player damage to its health, but I am trying to make this work for any two values that my.z ends up equaling, after the player falls.
And yes, to be honest, I believe I got this code from someone else a long time ago. I thought I understood enough of it to be effective for me, but I have unexpectedly run into this issue. When I solve this issue, it will allow me to understand it better.
|
|
|
Re: Falling Damage
[Re: Ruben]
#456962
12/17/15 07:23
12/17/15 07:23
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
OP
User
Joined: Jun 2010
Posts: 590
California
|
So, I notice that when I place this code in the program:
action player_code()
{
...
if(my.z > 49)
{
beep();
}
...
}
...the game beeps like crazy while the player is at my.z = 2333.827 . If I jump in the air (not stepping off a ledge), the game stops beeping while I am in the air, and resumes beeping once the player lands back on the ground. When the player steps off a ledge and falls in mid-air, the game stops beeping while the player falls, and starts beeping again once the player lands on the ground with a my.z of 49.267 .
|
|
|
Re: Falling Damage
[Re: Ruben]
#456963
12/17/15 07:50
12/17/15 07:50
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
OP
User
Joined: Jun 2010
Posts: 590
California
|
Okay, I see where I am falling (surprised why I did not notice it before):
action player_code()
{
...
var gravity_force = 2;
...
my.GRAVITY_VAR -= gravity_force * time_step;
...
c_move(me, move_vec, vector(0, 0, my.GRAVITY_VAR), USE_POLYGON |
IGNORE_PASSABLE | GLIDE);
...
DEBUG_VAR(my.z, 300);
...
}
It seems to me that my.GRAVITY_VAR should be affecting my.z while player is falling, but it shows nothing while player falls, judging by the DEBUG_VAR(my.z, 300); .
Last edited by Ruben; 12/17/15 07:52.
|
|
|
Re: Falling Damage
[Re: txesmi]
#456965
12/17/15 11:05
12/17/15 11:05
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
approach your problems with the theory behind the code .
"As an object falls, its speed increases because it's being pulled on by gravity. The acceleration of gravity near the earth is g = -9.81 m/s^2. To find out something's speed (or velocity ) after a certain amount of time, you just multiply the acceleration of gravity by the amount of time since it was let go of"
this is how the equation for calculating a falling object's velocity is described by a physics site , therefore given the theory and equations , you need simply the correct values to plug in to the equations under the correct conditions .
if you ever face a problem , remember that there are real world answers , to approach it .
Compulsive compiler
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|