I got following script:
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float movementSpeed;
public float rotationSpeed;
public float EXT_movementSpeedModifier;
Transform selfTransform;
Vector3 selfPosition;
Vector3 selfRotation;
float angleTurnal;
void Start() {
selfTransform = transform;
selfPosition = selfTransform.position;
selfRotation = selfTransform.rotation.eulerAngles;
}
void Update() {
Vector3 mousePos = Input.mousePosition;
mousePos.z = 5.23f;
Vector3 objectPos = Camera.main.WorldToScreenPoint (transform.position);
mousePos.x = mousePos.x - objectPos.x;
mousePos.y = mousePos.y - objectPos.y;
float angle = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
}
void FixedUpdate() {
// angleTurnal = selfTransform.eulerAngles.magnitude * Mathf.Deg2Rad;
/*if (Input.GetKey (KeyCode.RightArrow)) {
selfRotation.z -= rotationSpeed;
}
if (Input.GetKey (KeyCode.LeftArrow)) {
selfRotation.z += rotationSpeed;
}*/
if (Input.GetKey (KeyCode.UpArrow)) {
selfPosition.x += (Mathf.Cos(angleTurnal) * movementSpeed) * Time.deltaTime;
selfPosition.y += (Mathf.Sin(angleTurnal) * movementSpeed) * Time.deltaTime;
}
if (Input.GetKey (KeyCode.DownArrow)) {
selfPosition.x += Mathf.Cos(angleTurnal) * Time.deltaTime;
selfPosition.y += Mathf.Sin(angleTurnal) * Time.deltaTime;
}
selfTransform.position = selfPosition;
selfTransform.rotation = Quaternion.Euler(selfRotation);
}
}
Code isn’t mine, I just modified it to basics of my purposes. My idea behind it would be that GameObject (player in this case), turns around to current position of mouse, W would make it go forward, S would make it go forward but slower. But all it does when I press is W or E, is going to right faster or slower. Regardless where I have my mouse, it does turn, but it doesn’t move there.