x


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

more ▼

asked Sep 18, 2010 at 12:09 AM

Dino97 gravatar image

Dino97
1 16 10 10

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Sep 20, 2010 at 07:57 AM

Paulius Liekis gravatar image

Paulius Liekis
8.7k 75 79 110

(comments are locked)
10|3000 characters needed characters left

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( )

more ▼

answered Mar 25, 2011 at 03:12 PM

Mike Roam gravatar image

Mike Roam
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5056
x1545
x1200

asked: Sep 18, 2010 at 12:09 AM

Seen: 3394 times

Last Updated: Sep 18, 2010 at 12:09 AM