Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PlayerMovement : MonoBehaviour {
- Animator anim;
- public float maxSpeed = 5f;
- public float rotSpeed = 180f;
- float sensitivity;
- float shipBoundRadius = 0.5f;
- bool isMoveing = false;
- // Use this for initialization
- void Start () {
- anim = GetComponent<Animator> ();
- }
- // Update is called once per frame
- void Update () {
- //ROTATE Ship
- // Get Rotation Quaternion
- Quaternion rotation = transform.rotation;
- // Grab Z Euler Angle
- float z = rotation.eulerAngles.z;
- // Change Angle When Inputed
- z -= Input.GetAxis ("Horizontal") * rotSpeed * Time.deltaTime;
- // Make a new Quaternion with X = 0, Y = 0, Z = Our Angle
- rotation = Quaternion.Euler (0, 0, z);
- //Set rotation
- transform.rotation = rotation;
- //Input.GetAxis - 0 if not 0.num to 1 if forward -num if back
- //Transform is pos rotatation and scale
- Vector3 pos = transform.position;
- Vector3 velocity = new Vector3( 0, Input.GetAxis("Vertical") * maxSpeed * Time.deltaTime, 0);
- float screenRatio = (float) Screen.width / (float) Screen.height;
- float mWidth = Camera.main.orthographicSize * screenRatio;
- if (pos.y > (Camera.main.orthographicSize+shipBoundRadius)) {
- pos.y = -Camera.main.orthographicSize;
- }
- else if (pos.y < -(Camera.main.orthographicSize+shipBoundRadius)) {
- pos.y = Camera.main.orthographicSize;
- }
- if (pos.x > (mWidth+shipBoundRadius)) {
- pos.x = -mWidth;
- }
- else if (pos.x < -(mWidth+shipBoundRadius)) {
- pos.x = mWidth;
- }
- pos += rotation * velocity;
- transform.position = pos;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement