A d and left right arrow keys don't seem to respond after loading the script

no matter the torque my snowboarders speed stays the same

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class PlayerController : MonoBehaviour

{

[SerializeField] float torqueAmount = 1f;

Rigidbody2D rb2d;

// Start is called before the first frame update

void Start()

{

    rb2d = GetComponent<Rigidbody2D>();

}

// Update is called once per frame

void Update()

{

    if(Input.GetKey(KeyCode.LeftArrow))

    {

        rb2d.AddTorque(torqueAmount);

    }

    else if(Input.GetKey(KeyCode.RightArrow))

    {

        rb2d.AddTorque(-torqueAmount);

    }

}

}

Still can’t get my player controller script to work. no script errors but, pressing keys does nothing

Hi,

The torque does not have anything to do with the player’s speed. It is responsible for the rotation.

We give the player speed with the SurfaceEffector2D component. Have you already checked it? If so, try to increase the “Speed” value there to see if the behaviour in your game changes.


See also:

When I start to type “LeftArrow” or “GetKey” VSC doesn’t recognize it as a function.

The player moves just fine but cannot rotate

I rebuilt the project and it works now. Not sure what I had wrong. But problem is solved :slight_smile:

Thank you, Nina!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms