- Home /
Third-Person Camera keeps intersecting with terrain/buildings
I need to add some collider to the default Third-Person Camera so that it doesn't clip through the geometry/other objects. What should I do? Are there any code examples which add mouse controls to the Third Person Camera, like in a standard third-person shooter game with the right analog stick?
Also, what's the best way of making the down button work as 'backwards' rather than 'turn 180 degrees'?
Thanks.
Answer by MountDoomTeam · Sep 22, 2012 at 07:01 PM
hiya, add an invisible capsule around it with a collider as parent or child, is a quick fix, that's a tricky one! advanced games probably have complicated code to make the camera follow in the middle of corridors etc. do some more research about camera smoothers and third person camera control in unity, theres alot of talk about it.
here is some navigation code for a spaceship with shoot taken from worm game tutorial.
also chck out the mouse orbit scripts for mouse camera orbit rotations.
var speed = 15.0;
var rotspd = 10.0 ;
var bullitPrefab : Transform;
function Update ()
{
if ( Input.GetKey("mouse 1") )
{constantForce.relativeForce = 15000 * Vector3.forward
;}
else
{constantForce.relativeForce = Vector3.zero;}
if(Input.GetButton("forwards"))
{
transform.eulerAngles.x += rotspd * Time.deltaTime * 7;
}
if(Input.GetButton("backwards"))
{
transform.eulerAngles.x += -rotspd * Time.deltaTime * 7;
}
if(Input.GetButton("left"))
{
transform.eulerAngles.y += -rotspd * Time.deltaTime * 7;
}
if(Input.GetButton("right"))
{
transform.eulerAngles.y += rotspd * Time.deltaTime * 7;
}
// if(Input.GetButton("Fire1"))
//{
// var bullit = Instantiate(bullitPrefab, transform.Find("spawnPoint").transform.position, Quaternion.identity);
//bullit.rigidbody.AddForce(transform.forward *8000);
// }
}
backwards is opposite of this:
if ( Input.Get$$anonymous$$ey("mouse 1") ) {constantForce.relativeForce = 15000 * Vector3.forward ;}
Answer by T27M · Sep 22, 2012 at 07:55 PM
I watched a video on YouTube(Link) @ about 4.50. Its a devlog of him making a game.
Basically the way he had his 3rd person camera setup is to cast a ray from the player to a plane that is tracked to the player. The camera would the be placed on the point where the ray hits. If something got in the way of the plane say a wall for example then the camera would be placed on the wall where the ray hits.
Might be worth a try scripting that system up.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Player Laggs/Shakes while making movement[Android] 1 Answer
Problem with player movements 1 Answer