- Home /
Runescape Movement and camera rotation
The Player moves on clicked location by mouse
and Camera to rotate around the player when Left Right Up Down buttons pressed (just like runescape)
This may be difficult, but im sure a lot of people would like this idea
thanks ++
Answer by Scribe · Dec 03, 2010 at 07:58 PM
var object : Transform;
function Update () {
if (Input.GetKey(KeyCode.DownArrow)) transform.RotateAround (object.position, Vector3(-1, 0, 0), 20 * Time.deltaTime);
if (Input.GetKey(KeyCode.UpArrow)) transform.RotateAround (object.position, Vector3(1, 0, 0), 20 * Time.deltaTime);
if (Input.GetKey(KeyCode.RightArrow)) transform.RotateAround (object.position, -Vector3.up, 20 * Time.deltaTime);
if (Input.GetKey(KeyCode.LeftArrow)) transform.RotateAround (object.position, Vector3.up, 20 * Time.deltaTime);
}
this is an updated script: set the object that you want to rotate around as the player in the inspector after adding the script to the camera, this will rotate around your players position.
function Update () {
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.DownArrow)) transform.Rotate(1, 0, 0);
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.UpArrow)) transform.Rotate(-1, 0, 0);
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.RightArrow)) transform.Rotate(0, 1, 0);
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftArrow)) transform.Rotate(0, -1, 0);
}
this can be used to rotate the camera just add this script to the main camera unfortuantly although The_r0nin link to click to move will work it will not find a path round obstacles so it will not walk round a building and through the door, it will either walk through the wall (no collider) or keep walking into the wall. the best way to do this is by downloading a pathfinding project like Aron Granberg's pathfinder here
incase the hyperlink didn't work (it sometimes doesn't :P)
thanks for the answer Scribe but i need a script that the camera rotates like that but around the player. thanks anyway man
your welcome. I've added a new script below which should rotate around the characters position. hope it helps