- Home /
character and Camera rotate
hi all,i need help....im making rpg game and i don't know how to make something....When i press A or D my character going to left,what i need to do to make my character (with camera) rotate when i press A or D...
Example: Press A - My character and camera rotate in left like in world of warcraft when i rotate my camera my character automaticaly rotate with camera or when press a or d in wow my character and camera moves
sorry for bad english
Answer by Paulius-Liekis · Sep 20, 2010 at 07:57 AM
You can either parent your camera to character (or vice versa) to make it attached, or you can update camera position from script based on character's position.
Answer by Mike Roam · Mar 25, 2011 at 03:12 PM
After a few hours of messing around with various scripting suggestions, I got this working for controlling a simple cube.
I learned the hard way that integer math can destroy Time.deltaTime, and that editing a script does NOT change the copy of the script that is attached to a character.
// I called this script move.js and added it to my main character.
var sspeed = 5.0; // speed that the var turnSpeed : float = 90.0; // degrees per second. //Good to have ".0" or explicit "float" because int math kills the turning!!
function Update () { // Move Forward or Backward... // [default keys: w/s/fwd/bak = "Vertical" (z axis)] var z = Input.GetAxis("Vertical") Time.deltaTime sspeed; transform.Translate(0, 0, z);
// Turn Left or Right...
// [default keys: a/d/left/right = "Horizontal" (x axis)]
// beware: MUST do the math with explicit floats to avoid int round off!
var turnAngle : float = turnSpeed * Input.GetAxis("Horizontal") * Time.deltaTime;
transform.Rotate (0, turnAngle, 0);
} // Update( )
Your answer
Follow this Question
Related Questions
Sidescroller Turning 1 Answer
MMORPG Rotate Character 1 Answer
Rotate camera to character angle 0 Answers
Turning torso of character with mouse 0 Answers