Setting up torque keys not working

a, d keys and left, right arrows keys aren’t responding when pressed. Torque is set to 10

Any ideas?

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);

    }

}

}

Hi,

Have you already tried to add Debug.Logs to your code to see what is going on during runtime?

Check if Update gets called. If it does get called at runtime, check if the if-blocks get executed. If Update does not get called, it’s not surprising that the player does not rotate. The PlayerController script has to be assigned to the player game object.

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

Privacy & Terms