This is my first project and it has already stopped working. This is my code so can someone tell me the problem. It keeps saying error 1503
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playermovement : MonoBehaviour {
public float movementSpeed;
public Rigidbody2D rb;
float mx;
private void Update() {
mx = Input.GetAxisRaw(“Horisontal”);
}
private void FixedUpdate() {
Vector2 movement = new Vector2(mx * movementSpeed, rb.velocity);
rb.velocity = movement;
}
}
mx = Input.GetAxisRaw("Horisontal");
should be
mx = Input.GetAxisRaw("Horizontal");
That’s one thing. I will try to re-create your script now…
You also are using rb.velocity as a part of the Vector2 defining rb.velocity, try instead –
Vector2 movement = new Vector2(mx * movementSpeed, transform.position.y);
A Vector2 defines 2 dimensions, the X and the Y. X corresponds with left and right in 2D space in unity while Y corresponds with your Vertical movement. So a Vector2 should be seen as –
Vector2(X,Y). If I’m understanding correctly, you’re trying to move the player only left and right at the moment, so you need to maintain the gameObject current Y position during the AddForce method.
Thank you for your help
Its still not working. Thanks anyway
Nobody remembers error numbers except google.
How to report your problem productively in the Unity3D forums:
How to understand compiler and other errors and even fix them yourself:
https://discussions.unity.com/t/824586/8
If you post a code snippet, ALWAYS USE CODE TAGS:
How to use code tags: https://discussions.unity.com/t/481379
This line:
We know Vector2() constructor takes 2 floats (see documentation).
First argument looks good: mx is float, movementSpeed is float, so good.
But your second argument is a Vector2 (again, see documentation!), so that’s not gonna work.
You need to give the Vector2() constructor 2 floats.
Ok