Skip to content

Calls jump function multiple times. #6

@ItsSeendo

Description

@ItsSeendo

I tried following the tutorial and i got all the way to the end and when I tested it, it called the jump event both when it originally jumps and when it lands. any ideas?
`using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class playerMovement : MonoBehaviour
{
public movementScript ms;
public Animator animator;
public bool jumpAction;
private bool playerStopped;
private float stopTimer;

public float horizontalMovement;

public float runSpeed = 40f;
public bool jump;
public bool crouch;

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

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

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

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

    if(stopTimer >= 10)
    {
        animator.SetBool("IsSitting", true);
    }
    else if(stopTimer < 10)
    {
        animator.SetBool("IsSitting", false);
    }
}

public void OnLanding ()
{
animator.SetBool("IsJumping", false);
Debug.Log("Player Landed");
}

public void OnCrouching (bool isCrouching)
{
	animator.SetBool("IsCrouching", isCrouching);
}

void FixedUpdate ()
{
	// Move our character
	ms.Move(horizontalMovement * Time.fixedDeltaTime, crouch, jump);
	jump = false;
}

}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions