Game Design
- Nature Park
- Light
- Car
- VR Cam
Nature Park
- Nature Park
- Nature Park in Asset
Light
- Directional Light
- Position: (0, 3, 0)
Car
- Rigidbody
- Freeze Rotation: X, Z
Move_craft.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class move_craft : MonoBehaviour {
void Start () { }
void Update () {
float xrot_rate = 120 * Time.deltaTime;
float zmoverate = 5 * Time.deltaTime;
float dirx = Input.GetAxis("Horizontal");
float dirz = Input.GetAxis("Vertical");
this.transform.Translate(Vector3.forward * zmoverate * dirz);
this.transform.Rotate(Vector3.up*dirx*xrot_rate);
}
void OnCollisionEnter(Collision other){
print("hit with "+other.gameObject.name);
Debug.Log("avoid "+ other.gameObject.tag);
if (other.gameObject.tag == "obstacle")
Destroy(other.gameObject);
}
void OnTriggerEnter(Collider other){
print("Pass");
}
}
VR Cam
- Empty Object
Smooth Fallow.cs
using UnityEngine;
namespace UnityStandardAssets.Utility{
public class SmoothFollow : MonoBehaviour{
[SerializeField]
private Transform target;
[SerializeField]
private float distance = 10.0f;
[SerializeField]
private float height = 5.0f;
[SerializeField]
private float rotationDamping;
[SerializeField]
private float heightDamping;
void Start() { }
void LateUpdate(){
if (!target)
return;
var wantedRotationAngle = target.eulerAngles.y;
var wantedHeight = target.position.y + height;
var currentRotationAngle = transform.eulerAngles.y;
var currentHeight = transform.position.y;
currentRotationAngle = Mathf.LerpAngle(currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
currentHeight = Mathf.Lerp(currentHeight, wantedHeight, heightDamping * Time.deltaTime);
var currentRotation = Quaternion.Euler(0, currentRotationAngle, 0);
transform.position = target.position;
transform.position -= currentRotation * Vector3.forward * distance;
transform.position = new Vector3(transform.position.x ,currentHeight , transform.position.z);
transform.LookAt(target);
}
}
}
- Target: Car
- Distance: 3
- Rotation Damping: 10
- Height Damping: 10
- Left Camera
- Put under VR Cam
- Position: (-0.2, 0, 0)
- Right Camera
- Put under VR Cam
- Position: (0.2, 0, 0)
UI

