Hi guys,
I’ve run trough several posts and other questions here but can find me a helpful answer.
What I trying to achieve is that the crosshair follows the camera with a little delay.
Example Video: 1
I want it to be like that HUD and not animated. I don’t need the walking shake since my Player wont walk in my game.
Here is my Code so far:
using UnityEngine;
using System.Collections;
public class DynamicGUI : MonoBehaviour {
public float speed = 0.5F;
public float centerSpeed = 0.0001F;
public Transform camera;
public Texture crosshair;
private float slowX;
private float slowY;
private float lastX;
private float lastY;
private float offsetX;
private float offsetY;
private float xValue = 0.0F;
private float yValue = 0.0F;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
offsetX = Input.GetAxis ("Mouse X") * Time.deltaTime;
offsetY = Input.GetAxis ("Mouse Y") * Time.deltaTime;
lastX = camera.rotation.x;
lastY = camera.rotation.y;
slowX = Mathf.SmoothDamp(-offsetX, 0, ref xValue, centerSpeed);
slowY = Mathf.SmoothDamp(-offsetY, 0, ref yValue, centerSpeed);
}
void OnGUI (){
GUI.DrawTexture (new Rect(Screen.width/2 + slowX * Screen.width, Screen.height/2 + slowY * Screen.height, 16, 16), crosshair);
GUILayout.Label("SlowX: " + slowX);
GUILayout.Label("SlowY: " + slowY);
GUILayout.Label("Last X: " + lastX);
GUILayout.Label("Last Y: " + lastY);
GUILayout.Label("Offset X: " + offsetX);
GUILayout.Label("Offset Y: " + offsetY);
}
}
So I got it to center a bit slower but I cant get it smooth and more delayed.
Maybe I’m stuck within a method which cant be used for this.
I hope you can help me out at this. I am familiar with java and C#.
Best regards
Nitrosocke