Skip to content

Instantly share code, notes, and snippets.

@saturngamesss
Last active April 14, 2020 16:18
Show Gist options
  • Save saturngamesss/faf26c4de234412c9be4c4b9d9d47750 to your computer and use it in GitHub Desktop.
Save saturngamesss/faf26c4de234412c9be4c4b9d9d47750 to your computer and use it in GitHub Desktop.
Simple 2D airplane code for Unity Engine
//************** 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