Last active
April 14, 2020 16:18
-
-
Save saturngamesss/faf26c4de234412c9be4c4b9d9d47750 to your computer and use it in GitHub Desktop.
Simple 2D airplane code for Unity Engine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//************** REAL GAMES STUDIO *************** | |
//************************************************ | |
//realgamesss.weebly.com | |
//gamejolt.com/@Real_Game | |
//realgamesss.newgrounds.com/ | |
//real-games.itch.io/ | |
//youtube.com/channel/UC_Adg-mo-IPg6uLacuQCZCQ | |
//************************************************ | |
using UnityEngine; | |
public class Airplane : MonoBehaviour | |
{ | |
Rigidbody2D rb; | |
public float speed = 3.0f; | |
public float rotationSpeed = 3.0f; | |
// YOU make point and move it in front of object | |
public Transform point; | |
void Start() | |
{ | |
// YOU add Rigidbody2D to the object and gravity scale make on zero | |
rb = GetComponent<Rigidbody2D>(); | |
} | |
void FixedUpdate() | |
{ | |
float xAxis = Input.GetAxis("Horizontal"); | |
Vector3 pos = point.position; | |
// Move to point | |
transform.position = Vector3.Lerp(transform.position, pos, speed * Time.deltaTime); | |
// Rotate with object | |
rb.MoveRotation(rb.rotation + (-xAxis * rotationSpeed) * Time.fixedDeltaTime); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment