- Home /
How do I make a simple, 3rd person RPG-type camera behavior?
Hello! I'm a graphic artist, long time gamer excited and anxious to get into game development. Art and design are totally my thing but I hardly know squat about code and programming.
I'm putting together a 3rd-person RPG type of game and I want my camera to behave like an ordinaly, common 3rd person RPG type camera. How do I accomplish that?
A great example of the type of camera behavior I am looking for could be Legend of Zelda:OOT, Conker's BFD, Ninja Gaiden, GTA:Vice City, True Crime, etc, I am sure I could dig up a lot more if that is not helpful.
Otherwise the only way I could describe it is by referring to real-world mechanics. Imagine an elastic tether connecting the camera to the character. The camera stays fixed on the character but only moves when the characters runs away and tugs on the tether.
The SmoothFollow script would be okay except that it snaps behind the character. Lowering the damnp rotation fixes that, but then the camera hardly rotates at all. I'd like the camera to rotate to track the character and only move when the character moves away, but then only move near the character again, not snap to the back of the character as in the SmoothFollow script.
It is an insanely common and popular camera control style in RPGs but I am having hell finding the proper way to re-create it. Please, please do not respond with, "Google it." I have been googling it, youtubing it, UnityWiki-ing it, redditing it, I've probably tried a dozen different scripts not including my own butcher-coding of putting together the bits and pieces of script that I thought would get the job done and crossing my fingers for it to work.
Thank you in advance to anyone who can help me out! -Gyrant
All of the scripting I am using so far is JS, since it seems to be the most popular language for use in Unity3D.
Answer by TehWardy · Mar 20, 2013 at 11:48 PM
the closest i came to getting this working (from a quick try this evening) was to do the following ...
add third person controller to scene
select camera
add mouse orbit script to camera
drag and drop 3rd person controller on to "target" of mouse orbit script edit the mouse orbit script ...
function LateUpdate () { if (target && Input.GetMouseButton(1)) { x += Input.GetAxis("Mouse X") xSpeed 0.02; y -= Input.GetAxis("Mouse Y") ySpeed 0.02;
y = ClampAngle(y, yMinLimit, yMaxLimit); } var rotation = Quaternion.Euler(y, x, 0); var position = rotation * Vector3(0.0, 0.0, -distance) + target.position; transform.rotation = rotation; transform.position = position; }
That sort of does it ... the idea being that the camera now follows the player and when the right mouse button is held down moving the mouse rotates the camera.
It does this odd jumpy thing though (the camera acts like its constantly being nudged) a tiny bit each frame ... I get the impression theres a better way to do this or maybe smoothing might help but that's the idea right?
So close !!!