- Home /
rotate around ball
I'm going to rephrase my question because this isn't working. I'm looking for a script for rotating around your character (the ball), when you press the input keys (up,down,left,right)
If your character moves forward (up), the camera goes behind you (does nothing). If character turns left, the camera rotates 90 degrees right to follow you and stay behind you. if you press "down" the camera will rotate 180 degrees and follow you.
the only difference is you are not moving the ball, you are tilting the game board to make the ball roll around a maze; and the camera follows the ball in 3rd person.
This is used in every 3rd person (over the shoulder) game; this can't be hard.
Answer by tingham · Feb 08, 2012 at 04:36 PM
Move the camera to a position relative to (ballGameObject.transform.forward -1f) and have the camera look at the ball. ballGameObject.transform.forward -10f would put the camera ten units behind the ball, transform.up would work similarly.
The problem with using the ball's .forward is that if the ball is rolling, the camera will spin with it. It's a very trippy experience, let me assure you. x)
Use the forward of the game object for your positioning but spin the interior transform of the mesh item itself. If you're using a Sphere primitive then you can implement an empty game object as @Vicenti suggests below; animating the rotation of the sphere inside of the empty game object over it's X, Z axis as the ball rolls but transfor$$anonymous$$g position via the containing game object.
I'm already using a Smoothfollow script, provided with Unity, I just need to get the camera to rotate "behind" the ball when you are tilt the marble board (maze) in some direction.
The board is set to tilt forward first. +Z, but then you need to tilt it -X, to go Left. and I want the camera to follow the ball, as such. the camera will go to +X so it is behind the ball.
Answer by Loius · Feb 08, 2012 at 04:52 PM
Create an empty object, and give it:
var ball : GameObject;
function LateUpdate() {
transform.position = ball.transform.position;
transform.LookAt( transform.position + *insert ball velocity here* );
}
Make your camera a child of that object. The object will face the direction the ball is moving (you may need to make a special case for zero movement), and the camera should spin around with it.
You won't want to parent like this if you plan on doing any easing with your camera (which seems likely.)
I was thinking more like
if(Input.Get$$anonymous$$ey("left"))
{
rotate camera 90 degrees to +X location
}
kind of idea then if you do
if(input.Get$$anonymous$$ey("Up"))
{
rotate camera to 0 or -Z (initial start point).
}
I know what I want, I'm not perfectly sure how its written. Since I already have the, Smooth Follow script, I was thinking of making this secondary. and of couse
if(input = cameraAngle) { don't do anything. }
I'm a bit new to Unity, so I'm still learning.
Answer by apollo25 · Oct 28, 2014 at 11:26 AM
i have a solution. create another new gameoject and make it child of the character at centre of character(0,0,0). then make camera new gameobject's child and keep it at a desirable dist. which will be the radius at which the camera will rotate.camera should point at character in scene. now you can rotate the new gameobject using transform.rotate
Your answer
Follow this Question
Related Questions
[JS] Custom camera rotation resets on Var change? 0 Answers
Rotating the camera over a period of time 1 Answer
Forward and back movements with a camera emulating an isometric view 1 Answer
How do I get my camera to rotate around the y=0 coordinate it's looking at? 0 Answers
Rotating a camera and his object like an airplane simulator 2 Answers