- Home /
Issues with mouse moving camera
Hi all,
I'd like to start by saying that this script works fine, I just need some guidance on how to do three things (pointers are great don't need anyone to write my game for me !)
The mouse feels jittery, is there a way to smooth the movement?
I can't seem to think of how to stop scrolling right and left at certain points for example where the camera starts is point 0 the camera can only scroll left to say 100 and it can't exceed 100 left or go less than the initial position 0 right.
I'm (obviously) just getting started around here but I feel that constantly spamming the screen width a hundred times a second or whatever the rate is seems clunky, is there a smarter way to accomplish this?
I've tried moving the variable around places (function start, awake etc. but funny things start to happen with the borders. I used LateUpdate because I read that camera controls should be in there and not in update???
Anyways, Here's the little script
var CameraToMove:Camera;
var CameraSpeed = 10;
var Border : int = 50;
function LateUpdate ()
{
var WideScreen = Screen.width;
if (Input.mousePosition.x > WideScreen - Border)
{
CameraToMove.transform.Translate(CameraSpeed*Time.deltaTime,0,0);
}
if (Input.mousePosition.x < 0 + Border)
{
CameraToMove.transform.Translate (-CameraSpeed*Time.deltaTime,0,0);
}
}
So thanks for reading this giant block o' text, any hints or tips would be much appreciated!
Thanks for the leads Aeonlxion, I read about clamp and I thought I got it... I did not! So here is what I'm looking at, maybe if you could point where I'm wrong?
CameraTo$$anonymous$$ove.transform.position = Vector3($$anonymous$$athf.Clamp(CameraSpeed*Time.deltaTime, 1.0, 100.0) //this part I thought was the x position with a $$anonymous$$ x of 0 and max x of 100, but that doesn't seem right, it does stop the camera from moving left any further and when I move right it seems to move less than 1 to the x going back left brings it back to 0 , 80, -10); this I'm assu$$anonymous$$g is a flat y,z and it seems to be holding.
Thanks very much
Your answer
Follow this Question
Related Questions
Camera.main.ScreenToWorldPoint works within Unity editor, but not in builds 0 Answers
Make object follow mouse, while actually moving camera, instead of object 2 Answers
MousePosition input problem after rotating object. 0 Answers
ScreenToWorldPoint exclude objects or layers? 1 Answer
[Solved] Constraining a position within a radius (2D crosshair) 1 Answer