Skip to content

Instantly share code, notes, and snippets.

@resonantdoghouse
Created July 7, 2018 08:24
Show Gist options
  • Select an option

  • Save resonantdoghouse/35ab5b55e2987113b8dbd9ad9102aa43 to your computer and use it in GitHub Desktop.

Select an option

Save resonantdoghouse/35ab5b55e2987113b8dbd9ad9102aa43 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlanePilot : MonoBehaviour
{
public float speed = 10.0f;
// Use this for initialization
void Start()
{
Debug.Log("Plane Script Added " + gameObject.name);
}
// Update is called once per frame
void Update()
{
Vector3 moveCamTo = transform.position - transform.forward * 10.0f + transform.up * 5.0f;
float bias = 0.96f;
Camera.main.transform.position = Camera.main.transform.position * bias + moveCamTo * (1.0f - bias);
Camera.main.transform.LookAt(transform.position + transform.forward * 30.0f);
transform.position += transform.forward * Time.deltaTime * speed;
speed -= transform.forward.y * Time.deltaTime * 50.0f;
if (speed < 35.0f)
{
speed = 35.0f;
}
transform.Rotate(Input.GetAxis("Vertical"), 0.0f, -Input.GetAxis("Horizontal"));
float terrainHeightWhereWeAre = Terrain.activeTerrain.SampleHeight(transform.position);
if (terrainHeightWhereWeAre > transform.position.y)
{
transform.position = new Vector3(
transform.position.x,
terrainHeightWhereWeAre,
transform.position.z
);
}
}
}
@JosephV-desing
Copy link

using UnityEngine;
using System.Collections;

public class ShootDemo : MonoBehaviour {

Rigidbody projectile;
    public Transform Gun; 

public float speed = 20;
    GameObject obj = GameObject.CreatePrimitive(CreatePrimitive.Sphere); 



// Use this for initialization
void Start () {
projectile = getcomponent<Rigidbody>();
}

// Update is called once per frame
void Update () {

	if (Input.GetButtonDown("fire1"))
	{ 
	                gun.position = Instantiate(projectile,
		                                               transform.position,
		                                               transform.rotation)

		obj = transform.TransformDirection(new Vector3(0, 0,speed));

	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment