- Home /
Position icon lags while panning
I have an overhead orthographic camera that I can pan and zoom on a map. My character's position is shown using a DrawTexture. The problem is that when I'm panning around the screen, the DrawTexture is a frame or so behind my movement, so it looks like it's jumping around. How can I keep the texture from lagging and jumping?
GUI code: var Controller1 : GameObject;
var PositionIcon : Texture;
function OnGUI () {
var IconX : float;
var IconY : float;
IconX = camera.WorldToScreenPoint(Controller1.transform.position).x;
IconY = camera.WorldToScreenPoint(Controller1.transform.position).y;
GUI.DrawTexture(Rect(IconX-10,Screen.height-IconY-10,20,20),PositionIcon,ScaleMode.ScaleToFit, true);
}</pre>
Important part of panning script: var fullMapCam : Camera;
var panSpeed : float = zoomSize.025;
if(Input.GetButton("Fire1")&&(Input.GetAxis("Mouse X")!=0||Input.GetAxis("Mouse Y")!=0)){
fullMapCam.transform.position.x -= Input.GetAxis("Mouse X")panSpeed;
fullMapCam.transform.position.z -= Input.GetAxis("Mouse Y")*panSpeed;
Screen.lockCursor = true;
}
if(Input.GetButtonUp("Fire1")){
Screen.lockCursor = false;
}
Comment
Best Answer
Answer by Itinerant · Nov 14, 2012 at 10:18 PM
Ok, solving my own problems again. I'd still like other ideas on avoiding this issue, but I've come up with a workaround that works for me. Rather than using OnGUI, I've created a GUI Texture and made it follow my character around the screen. No more lagging behind.