- Home /
I'm using a spotlight cookie as my reticle and getting jitters?
Instead of using a 2d texture as a reticle for a top-down shooter, I want something that projects straight down onto the ground and distorts/warps as the cursor moves over undulations in the terrain, so I feel like a spotlight with a cookie for the reticle shape works well, but I'm running into a problem. It looks fine and dandy when the player controller (camera) isn't updating position - i.e. just mouse movements, but as soon as I move the character position and mouse, the 'reticle' starts getting jittery.
I have a feeling this is because the camera position is constantly updating while the mouse is updating, and there is some headbutting causing the jitters.
I have this script attached to an empty game object, and then a spotlight as a child of the game object. It's set to LookAt the player so the reticle is facing the right direction. I tried this without the LookAt and still get the jitters. Tried using a Projector but it still gets the jitters.
Is there a way around the jitters? Is there a better way to do what I'm trying to do? Should I just use 2d textures and GUI instead? :) Thanks in advance, guys!
public class Cursor : MonoBehaviour {
public Transform player;
void Update () {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity)){
transform.position = hit.point;
transform.LookAt (player);
}
}
}
Thank you for the reply, fafase. I tried swapping the LookAt to a LateUpdate, and the raycasting (flip flopping them) and still got the jitters. I'm using the default Unity SmoothFollow script and tried making that a LateUpdate, but still nothing yet - same ol' jitters.