I got this error when making dodge roll
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed;
public Rigidbody2D rb;
Vector2 movement;
public Animator animator;
public float roll;
private int dodgecount;
Vector2 dodgevect;
public float dodgeSpeed;
// Update is called once per frame
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
animator.SetFloat("Horizontal", movement.x);
animator.SetFloat("Vertical", movement.y);
animator.SetFloat("Speed", movement.sqrMagnitude);
if (Input.GetKeyDown(KeyCode.Space) && movement != Vector2.zero && dodgecount = 0){
dodgecount = 60;
dodgevect=movement.normalized;
}
if (dodgecount != 0) {
dodgecount -= 1;
rb.velocity = dodgevect.normalized * dodgeSpeed;
}
}
void FixedUpdate()
{
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
}
}
↧