#Dead player moves

1 messages · Page 1 of 1 (latest)

stiff jacinth
#

you have your HeartSystem

#

reference that from the player

#

then you can check if dead == true
and then dont run your input code

novel otter
stiff jacinth
#

thats a no

#

i can help you with the steps you are stuck on but you have to write the code

novel otter
#

ok np

#

how can i do it :>

novel otter
stiff jacinth
#

first step
make a public variable of type HeartSystem in your PlayerMovement2D class

novel otter
stiff jacinth
#

looks good

novel otter
#

and step two is... :>

stiff jacinth
#

mmm i see that disable the PlayerMovement2D component when your player dies

#

can you check that that happens when you die?

#

i did not see that code at first it should accomplish what you are trying to do

novel otter
#

this is the playermovement script

stiff jacinth
#

give me a second
i look into how we can fix that

novel otter
#

tyt

stiff jacinth
#
void OnDisable()
{
    rb.velocity = Vector2.zero;
}
#

that is what i would try

novel otter
#

where do i put it ?

stiff jacinth
#

it set the velocity (the movement speed) of the player to 0 if the player movemnt is disabled

#

PlayerMovement2D

#

i hope that the CharacterController2D not prevents this

novel otter
#
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class PlayerMovement2D : MonoBehaviour
{
    [SerializeField] private LadderMovement ladderMovementScript;
    public CharacterController2D Controller;
    private Rigidbody2D rb;
    public Animator animator;


    public float runSpeed = 40f;
    float horizontalMove = 0f;
    bool jump = false;
    bool crouch = false;
    
    
    
    


    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;

        animator.SetFloat("Speed", Mathf.Abs(horizontalMove));

        if (Input.GetButtonDown("Jump")){
            
            jump = true;
            animator.SetBool("IsJumping", true);
        }

        if (Input.GetButtonDown("Crouch")){

            crouch = true;

        }
        else if (Input.GetButtonUp("Crouch")){
            
            crouch = false;

        }
    }

    public void Onlanding (){
        animator.SetBool("IsJumping", false);
    }

    void FixedUpdate() 
    {
        // Move our character
        Controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
        jump = false;
        
    }
    void OnDisable()
    {
        rb.velocity = Vector2.zero;
    }



}
#

like this ?

stiff jacinth
#

yes

novel otter
stiff jacinth
#

ah ok
is the Rigidbody2D component on the same gamobject as the PlayerMovement2D ?

novel otter
#

yes

stiff jacinth
#

ok lets change
rb.velocity = Vector2.zero;
to
gameObject.GetComponent<Rigidbody2D >().velocity = Vector2.zero;

novel otter
#

It Works !!!!!

stiff jacinth
#

nice

novel otter
#

Thanks a lot i've been trying to fix it for like 6 hours and you solve it in minutes :>