Trouble with a Unity 2D movement script

lolstamp_DEV

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;
    }
}
Fredrik Schön

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() {

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Unity 2d Movement script issue

Unity 2d game movement script issue - unable to jump

Having trouble with 2D texture movement

Unity3D Player movement script

How can I refactor my 2d unity movement script to resolve the behavioral issues I have?

Stuttering movement in Unity 2D

Unity 2D joystick movement

Unity 2D draggable movement control

2D Ragdoll movement in unity

Physics movement for unity 2D

Player movement script like in FPS, Unity3d

Restricting movement of a 2d object to backward only in UNITY

Limiting 2D camera movement in Unity to edge of my map

Movement Code Affected by Fps in Unity 2D

Disable Diagonal Movement in Unity 2D (but fluctuates between the two)

2D Camera movement script throwing CS0428

Unity Player Movement Script is not working correctly

Flipping sprite in unity with weird movement script

trouble understanding movement along local and global space in unity

I'm trying to make a movement script where the character moves from side to side and it just stays to one side of the screen... (Unity 2D)

Unity 2d instantiating on mouse location trouble, Please advise

Unity 2D Jump script

Unity 2d jumping script

2D top-down point and click movement and rotation in Unity3D

Trouble with Unity Camera Script Expected ";" at line of code

Unity 2D Top Down Shooter movement issue C#

How can I change the window movement key when using Unity 2D?

Force on horizontal movement on unity 2D character controller is not working correctly

Why does my 2D movement in Unity only move up and left but not down and right?