- Home /
3rd person camera/movement
Hey guys I'm a new game maker here and I have all the skills I need to make the game look nice except for the coding aspect... What I am attempting to make is a 3rd person game with movement much like GTA 5 and I have been searching for a solution for a while. I figure it will be hard to make the player and the camera orbit separately but this is the kind of camera that is necessary for my game... I don't want videos showing me this at work. I need someone who can walk me through the process of coding all of it so I can customize it to my game. If anyone would like to help me with this project more I would love to talk because I basically know nothing about coding except how to read it and simple things I will need to customize it. Thank you for your time! -Skylar
I would recommend taking a look at the Bootcamp tutorial, or if you want to dig through the guts of some code, the first person controller stock prefab? Sorry If I'm not much help, but good luck!
Thanks ill do that! I tried pecking at the newest prefab but its just not what I'm looking for and $$anonymous$$y skills with coding are just not advanced enough to change it to what I want... also it doesn't have any camera modal I could use which is a large part of how I want the character to move...
Answer by Tekksin · Jun 17, 2015 at 10:37 PM
Third person cameras are pretty simple. Just make a camera and then make it a child of your player. Position it at the height and angle you see fit. It'll follow the player around. Moving the camera independently of the player's look-rotation is a different story though:
If you wanna go that route, you can trick unity. Just make a player, then make an empty gameobject and make that empty obj a child of the player. Then make the camera and make that a child of the empty gameobject.
player > empty > camera.
Then have the camera follow the empty gameobject. When you use the right thumbstick to pan the camera, or the mouse pointer to aim it elsewhere--however you wanna control that--have the empty begin to rotate. This way your player's rotation stays the same. Subsequently, it'll follow the player all the same because it's following the empty that is a child of the player.
Thank you, years later this answer is still helpful. Cheers
Answer by shadowunity3d · Jun 09, 2017 at 06:42 AM
Here is my answer and it works perfectly: Moves forward, Rotates and Collides with Other objects (Having RigidBody and Box/Capsule Collider). tThis is based from Burkhard's answer.
But befor all do this : Create an empty Object set it a child of your Player and drag your camera Object into your empty Object.
NB : You can place the camera behind your player to get a best view.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CubeControl : MonoBehaviour {
public float speed = 10.0f;
Rigidbody rb;
GameObject playerEmpty;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update () {
float Haxis = Input.GetAxis ("Horizontal");
float Vaxis = Input.GetAxis ("Vertical");
//Go Forward
if(Input.GetKeyDown(KeyCode.UpArrow))
{
//Works perfectly but does no longer collide
//rb.transform.position += transform.forward * Time.deltaTime * 10.0f;
//Not moving in the right direction
//rb.velocity += Vector3.forward * 5.0f;
rb.velocity += Camera.main.transform.forward * speed;
//rb.rotation() += new Vector3 (0.0f, headingAngle, 0.0f) * 5.0f;
//rb.velocity += gameObject.transform.localEulerAngles * Time.deltaTime * 10.0f ;
}
if(Input.GetKeyDown(KeyCode.DownArrow))
{
rb.velocity -= Camera.main.transform.forward * speed;
}
Vector3 rotationAmount = Vector3.Lerp(Vector3.zero, new Vector3(0f, 10.0f * (Haxis < 0f ? -1f : 1f), 0f), Mathf.Abs(Haxis));
Quaternion deltaRotation = Quaternion.Euler(rotationAmount * Time.deltaTime);
this.transform.rotation = (this.transform.rotation * deltaRotation);
}
}
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Orbit around an object 0 Answers
3rd person controller 0 Answers
3rd person controller camera passing through walls 0 Answers
3rd person player 0 Answers