Tried to look it up on your forums, I’ve stolen from here, stolen from there, this is where I’m left at:
using UnityEngine;
using System.Collections;
public class playerMovement : MonoBehaviour {
public float movementSpeed_MOD; // set as 1 in Editor
public float rotationSpeed_MOD; // set as 1 in Editor
Transform selfTransform;
Vector3 selfPosition;
Vector3 selfRotation;
float selfAngle;
void Start() {
selfTransform = transform;
selfPosition = selfTransform.position;
selfRotation = selfTransform.rotation.eulerAngles;
}
void FixedUpdate() {
selfAngle = selfTransform.eulerAngles.magnitude * Mathf.Deg2Rad;
if (Input.GetKey (KeyCode.RightArrow)) {
selfRotation.z -= rotationSpeed_MOD;
}
if (Input.GetKey (KeyCode.LeftArrow)) {
selfRotation.z += rotationSpeed_MOD;
}
if (Input.GetKey (KeyCode.UpArrow)) {
selfPosition.x += (Mathf.Cos(selfAngle) * movementSpeed_MOD) * Time.deltaTime;
selfPosition.z += (Mathf.Sin(selfAngle) * movementSpeed_MOD) * Time.deltaTime;
}
if (Input.GetKey (KeyCode.DownArrow)) {
selfPosition.x -= Mathf.Cos(selfAngle) * Time.deltaTime;
selfPosition.z -= Mathf.Sin(selfAngle) * Time.deltaTime;
}
selfTransform.position = selfPosition;
selfTransform.rotation = Quaternion.Euler(selfRotation);
}
}
I’ve attached this script to a player, which is an image, but the image makes strange movements. When you tell it to go forward it goes forward and slightly to the side. When you tell it to move left, it will turn right. I tried changing the sides (selfRotation.z += or -=). But I can’t get Unity to react, whenever I change it, it just switches sides entirely including the interaction, leaving it exactly same.
This is top-down game, where player can move their character forwards and backwards, and turn left and right with arrows.