The way I understand it, my character SHOULD be translating +X, -X, +Y, -Y, but instead it’s translating “left around mouse cursor” etc. I have no idea what happened, the code is simple enough.
Any tips? ideas?
(I know my bullet code is broken, I’m trying to fix that one before coming asking for help)
Thanks
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour {
public int spd;
public GameObject bullet;
GameObject firedBullet;
Vector3 mousePos;
Vector3 worldPos;
float angle;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.rotation = Quaternion.LookRotation(Vector3.forward, mousePos - transform.position);
if(Input.GetKey (KeyCode.W))
{
transform.Translate (0, (spd * Time.deltaTime), 0);
}
if(Input.GetKey (KeyCode.S))
{
transform.Translate (0, 0 - (spd * Time.deltaTime), 0);
}
if(Input.GetKey (KeyCode.A))
{
transform.Translate ( 0 - (spd * Time.deltaTime), 0, 0);
}
if(Input.GetKey (KeyCode.D))
{
transform.Translate ((spd * Time.deltaTime),0 , 0);
}
if(Input.GetButtonDown ("Fire1"))
{
firedBullet = Instantiate(bullet, transform.position, Quaternion.AngleAxis (90, Vector3.up) ) as GameObject;
}
}
}