-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
Click to move working and fixed iso camera. Camera isn't actually isometric but that is the best description I have for it without researching the real name.
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
public class ClickToMove : MonoBehaviour { | ||
|
||
public float speed; | ||
public CharacterController controller; | ||
|
||
public AnimationClip run; | ||
public AnimationClip idle; | ||
|
||
private Vector3 position; | ||
|
||
// Use this for initialization | ||
void Start () { | ||
position = transform.position; | ||
} | ||
|
||
// Update is called once per frame | ||
void Update () { | ||
if(Input.GetMouseButton(0)) // left mouse button | ||
{ | ||
// locate where the player clicked on the terrain | ||
locatePosition(); | ||
|
||
} | ||
|
||
// Move player to position | ||
moveToPosition(); | ||
} | ||
|
||
void locatePosition() | ||
{ | ||
RaycastHit hit; | ||
// cast ray from camera to mouse position. | ||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); | ||
|
||
if (Physics.Raycast(ray, out hit, 1000)) | ||
{ | ||
position = new Vector3(hit.point.x, hit.point.y, hit.point.z); | ||
Debug.Log(position); | ||
} | ||
} | ||
|
||
void moveToPosition() | ||
{ | ||
if (Vector3.Distance(transform.position, position) > 1) | ||
{ | ||
Quaternion newRotation = Quaternion.LookRotation(position - transform.position, Vector3.forward); | ||
|
||
newRotation.x = 0f; | ||
newRotation.z = 0f; | ||
|
||
transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * 10); | ||
controller.SimpleMove(transform.forward * speed); | ||
|
||
animation.CrossFade(run.name); | ||
} else | ||
{ | ||
animation.CrossFade(idle.name); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Horizontal Distance to the target is always fixed. | ||
For every of those smoothed values we calculate the wanted value and the current value. | ||
Then we smooth it using the Lerp function. | ||
Then we apply the smoothed values to the transform's position. | ||
*/ | ||
|
||
// The target we are following | ||
var target : Transform; | ||
// The distance in the x-z plane to the target | ||
var distance = 10.0; | ||
// the height we want the camera to be above the target | ||
var height = 5.0; | ||
// How much we | ||
var heightDamping = 2.0; | ||
|
||
// Place the script in the Camera-Control group in the component menu | ||
@script AddComponentMenu("Camera-Control/Iso Follow") | ||
|
||
function LateUpdate () { | ||
// Early out if we don't have a target | ||
if (!target) | ||
return; | ||
|
||
// Calculate the wanted height | ||
var wantedHeight = target.position.y + height; | ||
|
||
var currentHeight = transform.position.y; | ||
|
||
// Damp the height | ||
currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime); | ||
|
||
// Set the position of the camera on the x-z plane to: | ||
// distance meters behind the target | ||
transform.position = target.position; | ||
transform.position -= Vector3.forward * distance; | ||
|
||
// Set the height of the camera | ||
transform.position.y = currentHeight; | ||
|
||
// Always look at the target | ||
transform.LookAt (target); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.