- Home /
How To Make Camera Follow Bullet?
Hi, I'm new in Unity game development. I am design a third person shooter game. What I want is when player fires a bullet camera should follow that bullet to its target. What I did so far is:
camera.forward = shot.transform.forward;
Vector3 newTargetPosition = shot.transform.position + (Vector3.up*2) + (Vector3.forward*5);
camera.position = newTargetPosition;
camera.LookAt(shot.transform.position);
Problem facing: When player turn back and fires bullet camera follow bullet from the front instead of follow that bullet from the back.
Please suggestion what/where I'm doing wrong?
Thanks in advance.
try this wiil help you
var target : Transform;
// Rotate the camera every frame so it keeps looking at the target function Update() { transform.LookAt(target); }
All of the mentioned code in my last post is in update function.
$$anonymous$$y Problem is camera position is not always at the back of the bullet. It depends on the player/gun position. if player turn left camera follow the bullet but shows left side of the bullet.
I think following line has the problem: shot.transform.position + (Vector3.up*2) + (Vector3.forward*5); I multiply Vector3Up with 2 and Vector3.forward with 5. I did this because I want camera to follow bullet from a little distance. but still struggling how to solve this :[
Had u tried smooth follow camera for this this camera also working like object follow
Answer by Ruthra · Feb 04, 2013 at 11:39 AM
Maybe you should go simplier and temporary make the camera transform a child of your bullet GameObject, then back to your character controller when bullet hit target.
This way it wouldn't be affected anymore by your controller position or rotation.
Answer by anilgautam · Feb 04, 2013 at 11:06 AM
take the position of bullet and change the position of camera according to bullet position
camera.transform.position = bullet.transform.position I did this and everything is working fine. the only problem I am facing is: camera is exactly at the same position of the bullet and because of this bullet is not visible in the scene. what I want is; camera should follow bullet with a little bit of distance and height. To achieve this I add Vector3 UP and forward in current position of the bullet and assign it to the camera:
camera.transform.position = bullet.transform.position +(Vector3.up*2) + (Vector3.forward*5);
and by doing this camera follow the bullet fine only in one direction.