Cloud Stack Ninja

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Controller : MonoBehaviour
{
    public GameObject jumpEffect;
    public float speed;
    public float jumpforce;
    public Rigidbody2D rb;
    public float rotationtorque;

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    void Update()
    {
        if(Input.GetKeyDown(KeyCode.Space) && Mathf.Abs(rb.velocity.y) < 0.001f)
        {
            rb.AddForce(new Vector2(0, jumpforce * Time.deltaTime), ForceMode2D.Impulse);
            Instantiate(jumpEffect, transform.position, Quaternion.identity);
        }
        if(Input.GetKey(KeyCode.A))
        {
            rb.AddForce(new Vector2(-speed * Time.deltaTime, 0));
        }
        if(Input.GetKey(KeyCode.D))
        {
            rb.AddForce(new Vector2(speed * Time.deltaTime, 0));
        }
        if(transform.localEulerAngles.z > 0)
        {
            rb.AddTorque(-rotationtorque * Time.deltaTime);
        }
        if (transform.localEulerAngles.z < 0)
        {
            rb.AddTorque(rotationtorque * Time.deltaTime);
        }
    }
}

I keep spinning to the right and yes, I tried adjusting the values and even tried eulerAngles instead of localEulerAngles. Everything else is fine but my problem is on the last 2 if statements.



Read more here: https://stackoverflow.com/questions/64417022/cant-seem-to-make-this-player-controller-balance-in-unity2d

Content Attribution

This content was originally published by DanHasAPan at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: