#ThirdPersonMovement

1 messages · Page 1 of 1 (latest)

wintry cipher
#

Explain again what you are trying to achieve, how you are trying to achieve it, and what is happening instead.

Post any Errors.
If there's a tutorial involved, post link and any relevant timestamps.

ruby rock
#

It's based off of a tutorial. I've no clue as to why it doesn't work. The only part that isn't working is the part that detects how far my player has fallen (So that they can apply damage if they fall a certain height)

wintry cipher
#

Alright. Link the tutorial.

ruby rock
#

Quick little video on how to fall damage in Unity.

Thanks for watching!

Chapters

0:00 Intro
0:08 The preparations
1:40 Detecting when we "land"
2:40 Telling how far we fell
5:31 Implementing a minimum fall distance
7:23 So yeah...
7:49 Outro and Patreon thanks

----------------------------------------------------------------------------------...

▶ Play video
#

One thing is that they're using a rigidbody instead of a charactercontroller, but they don't reference it in their scripts.

wintry cipher
#

Alright. So your movement script is working fine, and now you're trying to add fall damage, by example of this tutorial.

ruby rock
#

Yes.

#

I forgot to add

    void Damage()
    {
        float fallDistance = startOfFall - transform.position.y;
        if (fallDistance > minimumFall)
        {
            hp.HeartCount -= 1;
            Debug.Log(transform.position.y);
        }
    }

In the code snippet I sent.

#

The "if falldistance > minimumFall"

#

minimumFall is the distance my player has to fall to take damage

wintry cipher
#

Alright.
So the first code link is the movement script alone?

ruby rock
#

I sent the relevant code using inline tags, the entire script is inside the link

#
   private void FixedUpdate()
   {
        if (!wasFalling && isFalling)
        {
            startOfFall = transform.position.y;
        }

        if (!wasGrounded && controller.isGrounded)
        {
            Damage();
        }

        wasFalling = isFalling;
        wasGrounded = controller.isGrounded;
   } 
  void Damage()
  {
        float fallDistance = startOfFall - transform.position.y;
        if (fallDistance > minimumFall)
        {
            hp.HeartCount -= 1;
            Debug.Log("Player Fell " + (startOfFall - transform.position.y) + " units");
        }
  }
wintry cipher
#

This is very important: I need an exact copy of the script at hand.

ruby rock
#

Ope, wait a second. I forgot to remove some debugging stuff.

wintry cipher
#

exact means exact - it's important that I know what you're sitting with, because we are in fact looking for some type of mistake.

#

anyway

#

How does the controller know it is falling?
Is there a specific part of the fall damage code* that is or isn't working?

#

corrected*

ruby rock
#
 bool isFalling { get { return (controller.isGrounded && _directionY < 0); }}
wintry cipher
#

This part is wrong:

&& _directionY < 0

_directionY is only ever a product of _jumpSpeed and multiplier

#

in the tutorial, how did they use what you have named _directionY ?

#

or rather, in place of it

ruby rock
#

Ah, I had to apply my versions of their variables to the script. They used a rigidbody to determine the velocity, however I don't have one. They did say that you could apply your own velocity script in that area, so I tried. I'll look for the proper one now.

wintry cipher
#

Should be simple enough. Though it's 2.30 am here, so I'm not feeling the genius right now 😅

ruby rock
#

I'll try this! Thanks

wintry cipher
#
private Vector3 velocity;
private Vector3 previous;

private void Update()
{
    velocity = (transform.position - previous) / Time.deltaTime;
    Debug.Log(velocity.y);
    // other code
    previous = transform.position; // must be at end of function
}
ruby rock
#

">" operator cannot be applied to operands of type "Vector3" ):

wintry cipher
#

ah

#

sec, I must have misunderstood that code

#

I understand why

#
private float velocity;
private Vector3 previous;

private void Update()
{
    velocity = (transform.position - previous).magnitude / Time.deltaTime;
    // other code
    previous = transform.position; // must be at end of function
}
#

This will, however, not allow you to differentiate between X and Y velocities - they are explicitly tied

#

Maybe it will be better 🤷‍♂️

ruby rock
#

Would I put previous or velocity into my isFalling bool?

wintry cipher
#

Look at the Data Types of velocity and previous

#

and look at the solution in the code segment

ruby rock
#

Ah, my bad*

wintry cipher
#

velocity is the thing you need for your isFalling check
in this code, you are using previous to calculate velocity

#

which is a position

#

Perhaps your character controller has a form of velocity

#
velocity = (transform.position - previous).y / Time.deltaTime;
#

that might work

#

It's getting too late for me to be any further helpful.
If you're still having issues tomorrow, I'll check by the thread. Good luck. o/