Search Unity

moveVelocity does not exist

Discussion in 'Editor & General Support' started by Squiddu, Jan 10, 2020.

  1. Squiddu

    Squiddu

    Joined:
    Jan 10, 2020
    Posts:
    5
    Following blackthornprod's video on top-down movement,
    I inputted code on a file named PlayerController.cs. However, I get an error message saying that the method I used (moveVelocity) doesn't exist:
    Assets\Scenes\PlayerController.cs(23,39): error CS0103: The name 'moveVelocity' does not exist in the current context

    Here is my code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerController : MonoBehaviour
    6. {
    7.     public float speed;
    8.  
    9.     private Rigidbody2D rb;
    10.  
    11.     void Start()
    12.     {
    13.         rb = GetComponent<Rigidbody2D>();
    14.     }
    15.  
    16.     void Update()
    17.     {
    18.         Vector2 moveInput = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
    19.     }
    20.  
    21.     void FixedUpdate()
    22.     {
    23.         rb.MovePosition(rb.position + moveVelocity * Time.fixedDeltaTime);
    24.     }
    25. }
     
  2. MetalDonut

    MetalDonut

    Joined:
    Feb 7, 2016
    Posts:
    127
    You haven't declared it, so Unity doesn't know what it is. Write " private Vector2 moveVelocity; " at the top somewhere, maybe underneath your RigidBody2D declaration.