Falling Damage

Posted By: Ruben

Falling Damage - 12/16/15 11:27

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:

Code:
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.
Posted By: Dico

Re: Falling Damage - 12/16/15 15:16

Use c_trace when player in air then when player on the ground calcule the deffrent between the first point in air and the point when player on the ground .
The distance between these two point its the damage health.
Posted By: Ruben

Re: Falling Damage - 12/17/15 04:36

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:

Code:
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.
Posted By: Ruben

Re: Falling Damage - 12/17/15 05:00

Even if I change the code to:

Code:
if(my.z < 0)
{
   beep();
}


or
Code:
if(my.z > 0)
{
   beep();
}


or
Code:
if(my.z == 0)
{
   beep();
}


or
Code:
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:
Code:
if(my.z > 0)
...


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.
Posted By: Anonymous

Re: Falling Damage - 12/17/15 05:44

^ both post
LMFAO!!!!

the player my.z is it's z location in the world.
Code:
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
Posted By: Ruben

Re: Falling Damage - 12/17/15 06:19

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.
Posted By: Ruben

Re: Falling Damage - 12/17/15 07:23

So, I notice that when I place this code in the program:

Code:
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 .
Posted By: Ruben

Re: Falling Damage - 12/17/15 07:50

Okay, I see where I am falling (surprised why I did not notice it before):

Code:
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); .
Posted By: txesmi

Re: Falling Damage - 12/17/15 10:08

When player touches the floor if player falling speed is faster than a fixed amount substract to the health.

Salud!
Posted By: Wjbender

Re: Falling Damage - 12/17/15 11:05

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 .
Posted By: EpsiloN

Re: Falling Damage - 12/17/15 11:22

Gravity
This one looks very good, but I have not used it yet. I think Superku wrote it.

Listen, long posts wont help laugh

Drop the code you're using and start from scratch, if you cant understand what you're using.
in your player, add a gravityMove function and in that function perform a c_trace as described in Superku's tutorial, check the distance and c_move down if needed.
When you get to this simplest form, you can start building a method for counting time passed or distance or speed of falling...
Posted By: txesmi

Re: Falling Damage - 12/17/15 11:38

Originally Posted By: EpsiloN
As for your my.z = NULL problem, I don't think my.z will become NULL while your entity is still existing, or maybe its the same if its 0, I haven't checked. But, I'd suggest never test position for NULL.


I am pretty sure the execution of 'DEBUG_VAR ( my.z, ... )' is conditioned by 'if ( c_trace(...) > 0 )'...

edited: crazy
Posted By: Ruben

Re: Falling Damage - 12/17/15 18:45

Okay, so when I put this code in my program:

Code:
action player_code()
{
   ...

   if(my.z != NULL)
   {
      beep();
   }

   ...
}



The game beeps like crazy while the player's feet are are the ground. If I press the space bar making the player jump in the air, or if the player steps off a ledge and falls in mid-air, the beeping sound stops taking place, until the player's feet land back on the ground. So, I would think that this would lead me to believe that my.z must equal NULL while the player is jumping or falling in mid-air.

However, when I put this code in the above code's place:

Code:
action player_code()
{
   ...

   if(my.z == NULL)
   {
      beep();
   }

   ...
}



...no beeping takes place at all, whether the player's feet are on the ground, the player is jumping, or the player is falling in mid-air. So, this seems to indicate that the player's my.z is not equal to NULL while the player is jumping or falling in mid-air.

If the player's my.z is not equal to NULL, I would think that the game would have been beeping like crazy in all the instances for the first scenario above, and not temporarily stopped while the player was jumping or falling in mid-air.

I am sure hopefully someone has run into this kind of anomaly?
Posted By: Ruben

Re: Falling Damage - 12/17/15 18:50

Originally Posted By: EpsiloN
Gravity
This one looks very good, but I have not used it yet. I think Superku wrote it.

Listen, long posts wont help laugh

Drop the code you're using and start from scratch, if you cant understand what you're using.
in your player, add a gravityMove function and in that function perform a c_trace as described in Superku's tutorial, check the distance and c_move down if needed.
When you get to this simplest form, you can start building a method for counting time passed or distance or speed of falling...

Thank you Epsilon. I will check your link out. Thanks again.
Posted By: Dico

Re: Falling Damage - 12/17/15 18:51

man what is the relation between damage and if(my.z == NULL) !!!
my.z == 0 , you just know if the model is in origin z or not , this can't help you if you have a terrain or a map that have stairs ...
Posted By: Ruben

Re: Falling Damage - 12/17/15 18:55

Originally Posted By: Dico
man what is the relation between damage and if(my.z == NULL) !!!
my.z == 0 , you just know if the model is in origin z or not , this can't help you if you have a terrain or a map that have stairs ...

If I knew that my.z = NULL, perhaps I can run a timer while this is true. Then depending on how much time it was, this will tell me how much damage to inflict on the player. That is why it seems like it might be helpful to know if my.z equals NULL or not.

As far as the my.z value on stairs, I do see a my.z value in DEBUG_VAR() that quickly decrements as the player runs down the stairs. When the player runs off the side ledge of the stairs and falls in mid-air toward the bottom, the my.z value in DEBUG_VAR() disappears completely, until the player lands on the ground, to where I see a much lower my.z value in DEBUG_VAR().
Posted By: Dico

Re: Falling Damage - 12/17/15 19:00

if you can send to me image that show me your level i will tell you if that work for you or not and i will understand too what you want to do exactly.
Posted By: Ruben

Re: Falling Damage - 12/17/15 19:52

Okay, this is really weird.

On another part of my program, I have a debugger z value on a panel, and it shows the player's z value at all times, even while it is in mid-air:

Code:
...

var player_z;

...

PANEL* pDisplay =
{
   ...

   digits (180, 64, 5, *, 1, player_z); // DEBUGGER:  POSITION COORDINATES
	
   ...

   flags = SHOW;
}

function player_loc()
{
   ...

   player_z = my.z;
	
   ...
}



For the DEBUG_VAR() debugger:

Code:
action player_code()
{
   ...

   DEBUG_VAR(my.z, 300);

   ...
}


or
Code:
action player_code()
{
   ...

   DEBUG_VAR(player_z, 300);

   ...
}



...the z value only shows up while the player is on the ground, and totally disappears while the player is in mid-air.
Posted By: Wjbender

Re: Falling Damage - 12/17/15 19:56

Originally Posted By: Ruben
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:

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


if you look at your code ruben , the condition under which you display the z value ,falls under the condition that the player is on the ground ,therefore it will only show when on the ground ...
Posted By: Ruben

Re: Falling Damage - 12/17/15 20:04

Thank you Wjbender! I placed the DEBUG_VAR(my.z, 150) before the c_trace, and now the z value is showing at all times! Wow, I feel embarrassed. :-)
Posted By: Ruben

Re: Falling Damage - 12/17/15 20:08

Okay, I am sure that I can figure out how to inflict falling damage on the player now. Thank you again Wjbender! :-)
Posted By: Wjbender

Re: Falling Damage - 12/17/15 20:09

there are little hints in the reply's , places here and there without trying to be embarrassing ,such to try and nudge you towards seeing it , but don't worry happens to anyone.
Posted By: Ruben

Re: Falling Damage - 12/17/15 20:17

I am sure I was missing the hints. I really do appreciate all the help you all give, helping this struggling programmer along.
Posted By: Ruben

Re: Falling Damage - 12/17/15 21:46

Okay, I feel I am getting close, but not quite a cigar.

When the player jumps and falls downward, or falls downward in mid-air after stepping off a ledge, the game is now beeping like crazy, when I use the below code, and stops beeping when the player's feet land on the floor (which is good):

Code:
action player_code()
{
   ...

   DEBUG_VAR(my.GRAVITY_VAR, 225); // DECREMENTING RAPIDLY
                                   //    WHEN FALLING.

   if(my.GRAVITY_VAR < -3.80)
   {
      beep(); // BEEP IS WORKING WHEN PLAYER IS FALLING,
              //    BEEPING LIKE CRAZY WHEN PLAYER FALLS

      timer(); // TIMER SHOULD START WHEN PLAYER FALLS
				
      if(my.GRAVITY_VAR >= -3.80)
      {
         time_elapsed = timer(); // TIMER SHOULD END WHEN 
                                 //    PLAYER LANDS ON GROUND,
                                 //    AND RECORD TIME IN
                                 //    time_elapsed VARIABLE
      }
   }

   DEBUG_VAR(time_elapsed, 275); // DISPLAYS time_elapsed 
                                 //    VARIABLE, WHICH IS 
                                 //    STAYING AT 0, EVEN
                                 //    AFTER PLAYER DROPS

   c_move(me, move_vec, vector(0, 0, my.GRAVITY_VAR), USE_POLYGON | 
      IGNORE_PASSABLE | GLIDE);

   if(c_trace(my.x, vector(my.x, my.y, my.z - my.FEET_HEIGHT), IGNORE_ME | 
      IGNORE_PASSABLE | IGNORE_PASSENTS | USE_POLYGON)) 
   {
   
   ...		

   }

   ...
}



When the player falls downward, I notice the player's my.GRAVITY_VAR value rapidly decrementing below -3.80, to anywhere like -24 or so, until the player's feet land on the ground, to where my.GRAVITY_VAR goes back above or at -3.80 or so.

The only problem is that time_elapsed is staying at 0. The timer does not seem to be starting.

Does anyone see a glaring problem that I am just not noticing, that is making the timer not start, or work?
Posted By: Dico

Re: Falling Damage - 12/17/15 21:52

:[
Posted By: Wjbender

Re: Falling Damage - 12/17/15 21:54

>= is nested inside of <= ..again
Posted By: Ruben

Re: Falling Damage - 12/18/15 01:50

It looks like I will have to go by distance to give falling damage to the player, rather than time. The time_elapsed value seems to change, when done over and over again with the same exact scenario.
Posted By: Anonymous

Re: Falling Damage - 12/18/15 02:33

I'm not allowed to say this, because a moderator admonished me before.
But if you pay me, I'll just write it, with a timer for fall time to damage rate.

But for free info, when using timers, makes sure time_step is in place, also you need extra steps to keep the frame rate in line, last if testing in window mode - for heavens sake lock the fps to 60 or you random fps shift can be as large as -100/+100 fps

Posted By: Ruben

Re: Falling Damage - 12/18/15 02:52

I finally got it to work! Thank you all for your help, especially Wjbender. Your advice started the avalanche of me figuring it out. Thank you.
Posted By: Ruben

Re: Falling Damage - 12/18/15 02:53

Originally Posted By: Dico
if you can send to me image that show me your level i will tell you if that work for you or not and i will understand too what you want to do exactly.

I am sorry Dico, I did not mean to seem like I was ignoring you. I tried to send some images from my local computer, with no luck. I am guessing I have to send the images from a website.
Posted By: EpsiloN

Re: Falling Damage - 12/18/15 20:26

Originally Posted By: Ruben
Code:
action player_code()
{
   ...
   if(my.GRAVITY_VAR < -3.80)
   {
      beep(); // BEEP IS WORKING WHEN PLAYER IS FALLING,
              //    BEEPING LIKE CRAZY WHEN PLAYER FALLS

      timer(); // TIMER SHOULD START WHEN PLAYER FALLS
				
      if(my.GRAVITY_VAR >= -3.80)
      {
         time_elapsed = timer(); // TIMER SHOULD END WHEN 
                                 //    PLAYER LANDS ON GROUND,
                                 //    AND RECORD TIME IN
                                 //    time_elapsed VARIABLE
      }
   }
   ...
}



Aside from the pointed out nested "<" ">=" (which excludes the nested if from ever happening), I'll give you a tip on using these methods in a better way.
Making your gravity function separate from your player function gives you another possibility, to nest a while loop inside it.
Or even, separating the counting time function from the gravity function will still keep the gravity active while looping in its own while loop to count...

Meaning:
Code:
function fallTimeCounter() {
    while(1) {
        if( my.GRAVITY_VAR < -3.80 ) {
            timer();
            while( my.GRAVITY_VAR < -3.80 ) {
                wait(1);
            }
            time_elapsed = timer();
        }
        wait(1);
    }
}



Calling this in the beginning of your player or gravity function will make it work parallel to your gravity or player functions without interrupting them, but still counting the fall time.

Make sure that time_elapsed is a globally defined variable! (or a player skill, if you don't want global stuff.)
Posted By: Anonymous

Re: Falling Damage - 12/18/15 23:15

you don't need a timer so to say
Code:
var t_start=0;
var t_end=0;
var time_elapsed=0;

funcrion blah()
{

.....if(is==falling_start)
{
 if(!t_start)
  t_start=total_secs;

}
if( stopped == falling)
{
t_end=total_secs;
time_elapsed=t_end-t_start;
t_start = 0;
}



You should not need a measure smaller then 1 second, however if you feel you do, total_tick can be used and 16 ticks == 1 second.

lol
Posted By: Anonymous

Re: Falling Damage - 12/18/15 23:45

now lets use simple logic for falling and end of falling

Code:
vars...

function blah()
{
var last_z=0;
.....
while(..)
{
...... 
last_z=my.z;
c_trace(....)
if(a drop below)
grav = -50*time_step;
else
grav = 0;

c_move(....vector(x,x,grav)..)
if(grav) // unneeded check
if(my.z<last_z) // did the player drop?
{
if(last_z-my.z == grav) // did you fall unchecked
 // or
if(last_z-my.z > some measure) // did you drop more then a foot step??
{
  in_air = TRUE;
  if(!t_start)
  t_start=total_secs;
}
}
if(!grav) // c_trace found ground
{
if(my.z >= last_z)
{
  if(t_start)
{
  in_air = FALSE;
  t_end=total_secs;
  time_elapsed=t_end-t_start;
  t_start=0;
}
}
my.health -=time_elapsed*my.fall_damage;
time_elapsed=0;
}
}
}



Blah blah blah.... You'll never really learn this way. Blah Blah, I'm a lite-c vampire Blah Blah

lol
Posted By: EpsiloN

Re: Falling Damage - 12/19/15 08:01

Originally Posted By: Malice
you don't need a timer so to say

Yes. I only meant to point out to him that a separate function will run in parallel while counting laugh the actual implementation depends on the programmer's experience and preference and surrounding code.

This is why I suggested he starts from scratch. laugh We can give him 10 different ways, but while he's keeping his whole function a secret, nobody can help him but the author of this function...
Posted By: Anonymous

Re: Falling Damage - 12/19/15 20:39

Quote:
We can give him 10 different ways, but while he's keeping his whole function a secret, nobody can help him but the author of this function...


I'm trying to help him ..lol

Glad you see the top secret crap too. It's like he got his hands on someone else's HDD full of code, no sure who.... wink
Quote:
This is why I suggested he starts from scratch.

Cut and paste and hack and mod, is a good way to play with code and learn. But a terrible way to create a project. Hell I've hacked up Superku's code and more the older examples. But not because line x and line y cause effect z. There are still pieces of code Super has given me that I never use, because I don't use others idea of code till I understand it.
If you do not understand both the actual actions in a lines of code and the governing logic, you can not effectively use them in any implementation. You can play and test to figure these things out.
Having no idea HOW a piece of code does, only WHAT it's end effect is, then plugging play and hack and mod is foolish.
© 2024 lite-C Forums