- Home /
How would I create a smooth movement for my flashlight in my game?
I wanted my flashlight in my game have a smooth rotation instead I being exactly in the middle of the screen, not slow but have that smooth and realistic feel to it. I have been trying for the last 2 weeks and can't get any of my scripts to work :(
SO do you mean that when you turn, the flashlight is offset to the center of the screen then takes a moment to align back to center?
Ins$$anonymous$$d of the flashlight as a child of the camera, use an empty gameObject as a placemarker. Then lerp/slerp the position and rotation of the flashlight between its current position and the placemarker position.
Answer by Lili-Shi · Jul 22, 2017 at 05:37 PM
Assuming you have a first-person type of game, and a 3D-Model representing the flashlight or at least it being held, you could do the following:
-Attach the Light-source of the flashlight, from where you want to shine
-Create script, that moves whatever it is your Light-source is attached to smoothly between a given set of points in space/offsets. Think of Vecter3.Lerp, Vector3.Translate, Vector3.MoveTowards and such.
or, if you are more comfortable using the Animator
-Create single animation clips, where, at the very first frame of each clip, the Light-source/flashlight is at a different position in space
-Wire each clip up to be in a continueous loop and also let Unity blend between the animations.
Violá.
Greets!