#my movement script doesn't work...

1 messages · Page 1 of 1 (latest)

finite copper
#

i have a 2d project and its completely blank except for a single triangle. i want it to move but i cant make it move. i added a movement script and i tried to use wasd and the arrow keys and nothing worked. i adjusted the speed and whatnot and made sure my rigidbody2d was set up correctly. i literally just can't figure it out. i've also tried rigidbody2d.addforce but i probably wasn't using it right.

here is my PlayerController.cs: ```csharp
using UnityEngine;

public class PlayerController : MonoBehaviour
{
public float speed = 5;

Rigidbody2D rb;

void Start()
{
    rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
    float horizontalInput = Input.GetAxis("Horizontal");
    float verticalInput = Input.GetAxis("Vertical");

    Vector2 movement = new(horizontalInput, verticalInput);

    rb.linearVelocity = movement * speed;
}

}


btw there aren't any errors.
naive totem
#

are you sure the component is attached to the correct object

honest cosmos
#

Maybe show the inspector for this instance of the Player Controller component

finite copper
#

yeah i only have one object

honest cosmos
#

If speed were to be zero, you'd lose all motion. Also, you should be polling input in regular update.

honest cosmos
#

If you're just modifying velocity, you'd only need the regular Update function and not FixedUpdate

finite copper
naive totem
#

using GetAxis in FixedUpdate is fine, it's querying the current state of the input, it's not checking if the keys were just pressed so it's perfectly fine

finite copper
naive totem
#

i'm betting on the classic 6.1 error of using the input manager when the input system is set as default. of course that would show errors in the console at runtime

honest cosmos
#

Check the console log or rather show us the Unity Editor console window

finite copper
#

wow alright

#

thats definitely it

#

but i dont understand it

finite copper
#

whats the input system vs the input manager

naive totem
#

there are links on that page that will explain what each one is