lolstamp_DEV
lolstamp_DEV

Reputation: 43

Trouble with a Unity 2D movement script

I am working on my new unity project to release it on itch.io. When I write this code that my friend gave me (he is also making a platformer) it gives me the same error:

Assets\Scripts\PlayerMovement.cs(13,57): error CS1061: 'Rigidbody2D' does not contain a definition for 'Velocity' and no accessible extension method 'Velocity' accepting a first argument of type 'Rigidbody2D' could be found

I don't know what all of this means.

using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour{
    public float movementSpeed;
    public Rigidbody2D rb;
    
    float mx;
    private void update() {
        mx = Input.GetAxisRaw("Horizontal");
    }
    
    private void FixedUpdate() {
        Vector2 movement = new Vector2(mx * movementSpeed, rb.Velocity.y);
        
        rb.Velocity = movement;
    }
}

Upvotes: 1

Views: 494

Answers (1)

Fredrik
Fredrik

Reputation: 5108

RigidBody2D's property velocity is with a small letter v.

rb.velocity = movement;

rb.velocity.y

Also, I can see that your Update() method has a lowercase u. It should be capitalized as such:

Update() {

Upvotes: 1

Related Questions