As of now, I have a spaceship with the MouseLook script attached to it to make it move with the mouse (As well as a cursor-locking script) and a camera attached to the ship via the hierarchy. The control handles well, but because the camera and ship motion are so well-timed with the mouse movement, it makes my ship look like it’s fixed to the screen. Is there a way that I can make the camera “Lag behind” by a very short amount of time in order to fix this?
1 Answer
1The easiest and quickest way would be to use a Lerp function.
Just put this line into your camera script:
transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * 2.0f);
targetPosition is a Vector3 and is the position you want the camera to end up at. You can change the value at the end to increase or decrease the speed of the smooth motion.
I don't have a camera script. I simply put the main camera into the hierarchy of the ship. Could you provide the rest of the script that I need?
– XMatrix2XThere is a smooth fallow camera script in the scripts assets, maybe you should try that. Remove the camera from your object hierarchy into it's own and attach the smooth follow to you camera and give the target your object.
– gajdotI've tried using that, but it renders the crosshair useless, as when the ship turns, the crosshair does not, making it stay on the center of the screen.
– XMatrix2XCould you post a screenshot? If you doing it right it should follow your ship as needed.
– gajdotHere is an image if what I mean.![alt text][1] [1]: http://i.imgur.com/rhD7dPz.png
– XMatrix2X