- Home /
Problems with Camera (Camera keeps looking at the feet of my character)
public Transform target; // A variable that stores a reference to our Player
public Vector3 offset; // A variable that allows us to offset the position (x, y, z)
public float rotateSpeed = 5;
void Start()
{
offset = target.transform.position - transform.position;
}
void LateUpdate()
{
float horizontal = Input.GetAxis("Mouse X") * rotateSpeed;
target.transform.Rotate(0, horizontal, 0);
float desiredAngle = target.transform.eulerAngles.y;
Quaternion rotation = Quaternion.Euler(0 ,desiredAngle, 0);
transform.position = target.transform.position - (rotation * offset);
transform.LookAt(target.transform);
}
}
Hello! So, I've been trying to make a third person shooter, and for that, I needed a camera that would work. So I got this code from a website (https://code.tutsplus.com/tutorials/unity3d-third-person-cameras--mobile-11230) and decided to try it out. The camera seems to move along the x-axis when I move my mouse, so thats good, but the problem is, the camera keeps looking at the feet of my character, instead of forwards. I don't really understand the code all that well so I couldn't find a solution myself yet, so I was hoping to find some help here. I also can't figure out how to get the camera closer to my character. So, if any of you could help me find a solution to both or either one of my problems, I would be very grateful. Also, please tell me if you need additional information. I also dont expect you to code anything, simple instructions are just as good.
Answer by mcmount · May 19, 2018 at 07:01 PM
Add this to the beginning: public Transform Looktarget; This way you can define your cam to look any object, in this case probably player head or player hip etc. Then, change transform.LookAt(target.transform); TO: transform.LookAt(Looktarget.transform); Haven't tested, hopefully works.
First of all, thanks for your comment. Second of all, I'd like the camera to look forward, and not at any object. Right now, the rotation on the x-axis is set so that the camera looks at the feet of my soldier and i cant edit the rotation, because it keeps changing back.
well, your camera must look the character,this is 3rd person view, right? Your problem is that your character center point is in his feets, that's the usual character setup. Ins$$anonymous$$d of looking his feets, you need your cam to look something else in his hierarchy. Just make a dummy object, make it a child of hip/head or chest and make the dummy the Looktarget object. Hit play, move that dummy object around in scene view and you'll figure out how it works. LookAt always takes the world position of the object, and for character parent that's usually the ground plane.
Hey! So, I did what you said and I can confirm that my Camera is no longer looking at the feet of my character. Thank you very much for your help!
Your answer
Follow this Question
Related Questions
[Please Help!] How Can I Make The Tip Of My Ship Follow My Cursor? 0 Answers
Need Help Flipping my character depending on if the mouse is left or right. 1 Answer
How can I limit the rotation on the Y axis so the player cant spin the camera 360 in an FPS game? 0 Answers
UI button keyboard input into typing game ,UI button keyboard to input to Typing Game 1 Answer
Help!Crash! FatalError"Callback registration failed kMaxCallback" 1 Answer