2D player controls

hi please help
I’m new to unity

i need to control my player from top down view
left stick controls only
need the player to rotate to the position of the left stick is pointing & move forward
3215254--246257--man-draw0.png

here my script but doesn’t really work , I’m missing something

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

public class NewPlayerMove : MonoBehaviour {

public float speed;

private Vector3 moveDirection = Vector3.zero;
private Rigidbody2D controller;

void Start()
{
// Store reference to attached component
controller = GetComponent ();
}

void Update()
{
moveDirection = new Vector3(Input.GetAxis(“LR”), Input.GetAxis(“UD”), 0f);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;

transform.rotation = Quaternion.Euler(0f, 0f, Input.GetAxis(“LR”));

}

void FixedUpdate ()
{
controller.AddForce(moveDirection);
}
}

A few thoughts.

  • Please use code tags when posting code.

  • Don’t use physics for a game like this. It’s just asking for trouble. Just delete the Rigidbody (and the entire FixedUpdate method).

  • Your computation of moveDirection looks reasonable to me. (If you just pass moveDirection * speed * Time.deltaTime to transform.Translate, you’ll probably have that part solved.)

  • The rotation code looks all wrong, though. What you need to do is use Mathf.Atan2 to calculate the angle represented by the joystick. And then set your rotation accordingly.

HTH!