i have done code using a prefab joystick system however i can’t figure out how to get it to rotate. i am using this pack Joystick Pack | Input Management | Unity Asset Store. here is the code i am using for my movement/rotation. it is very messy.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerController : MonoBehaviour
{
public float speed;
public float jumpforce;
private float moveinput;
private Vector2 rotation;
public Joystick joystick;
private Rigidbody2D rb;
private bool facingright = true;
private bool isgrounded;
public Transform groundcheck;
public float checkradius;
public LayerMask whatisground;
private int extrajumps;
public int extjump;
void Start()
{
rb = GetComponent();
extrajumps = extjump;
}
void FixedUpdate()
{
isgrounded = Physics2D.OverlapCircle(groundcheck.position, checkradius, whatisground);
moveinput = joystick.Horizontal;
rotation = joystick.Direction;
rb.velocity = new Vector2(moveinput * speed, rb.velocity.y);
rb.rotation = rotation;
}
void Update()
{
float verticalmove = joystick.Vertical;
if (verticalmove >= .5f && extrajumps > 0)
{
rb.velocity = Vector2.up * jumpforce;
extrajumps–;
} else if(Input.GetKeyDown(KeyCode.W) && extrajumps == 0 && isgrounded == true)
{
rb.velocity = Vector2.up * jumpforce;
}
if (isgrounded == true)
{
extrajumps = extjump;
}
}
void Flip()
{
facingright = !facingright;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
public void TakeDamage()
{
SceneManager.LoadScene(“DED”);
}
private void OnTriggerEnter2D(Collider2D collision)
{
spring hit = collision.GetComponent();
if (hit != null)
{
rb.velocity = rb.transform.up * 30;
}
}
}