1
\$\begingroup\$

I'm stuck with a problem: I can not make my camera stop rotating after character.

What I already have tried: using empty game object with rigid body and locked rotation and make it parent of camera, while player being the parent of object. Also, I've tried using few scripts from web, that did not help.

Right now I'm bad with using JS in Unity (can handle JS on website, but I dont know how to integrate it for now) and practicing the basics, making easy 2.5d platformer with basic features, so I can not write code for now.

\$\endgroup\$
1
  • 4
    \$\begingroup\$ Can you clarify how your camera is controlled? Is there a script for controlling the Camera, or perhaps it's parented to something else that is moving? \$\endgroup\$ Commented Nov 12, 2013 at 0:05

1 Answer 1

2
\$\begingroup\$

This is a pretty straightforward coding problem, so don't shy away from writing a custom script to handle this problem. You just need to:

  • Create a new script
  • Double click that script to edit it
  • Add a public variable at the top to link the target (in C# you'd want to declare this variable as Transform, but I don't think you need to type variables in JS)
  • In the Update() function that is created with the basic script template, make this.transform.position = Vector(target.position.x, target.position.y, camera offset)
  • In the Unity Editor drag this script onto the camera to set it as a component of the camera
  • Drag the target object into the target variable of the component

The Update() function runs over and over while the game is running, so what this script does is position the camera every frame to move with the target, but the script doesn't affect the camera's rotation.

\$\endgroup\$
2
  • \$\begingroup\$ Small improvement: You will probably want to the z-part of the cameras position to a fixed value \$\endgroup\$
    – floAr
    Commented Nov 12, 2013 at 6:43
  • \$\begingroup\$ Good point. That's what I was getting at about the camera offset, but I worded that poorly so I'll edit that \$\endgroup\$
    – jhocking
    Commented Nov 12, 2013 at 14:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .