- Home /
Character rotation on foot?
Hello, I have a problem. When rotating my character he rotates on one foot. I want the rotation to be directly in the middle of him, My entire code is here:
#pragma strict
public var Dest : boolean = false;
var speed : float;
var rotateSpeed : float = 3.0;
var MisslePREF : Transform;
var jumpSpeed : float = 3.0;
var Health : int = 100;
var Mainplayer : Transform;
var CSpawn : Transform;
var DPlayer : Transform;
var isGrounded : boolean;
function Start () {
Screen.lockCursor = false;
Health = 100;
Physics.gravity = Vector3(0, -115.0, 0);
}
function Update (){
Screen.lockCursor = true;
if(Health <= 0){
Respawn();
}
Screen.lockCursor = true;
if(!animation.isPlaying){
animation.CrossFade ("fps_idle");
animation["fps_idle"].speed = 0.5;
}
if(Input.GetButton("forward")){
transform.position += transform.right;
animation["fps_run"].speed = 1;
animation.CrossFade("fps_run");
}
if(Input.GetButton("backward")){
transform.position -= transform.right;
animation.CrossFade("fps_back");
}
if(Input.GetButton("left")){
transform.position += transform.forward;
animation.CrossFade("fps_strafe_left");
}
if(Input.GetButton("right")){
transform.position -= transform.forward;
animation.CrossFade("fps_strafe_right");
}
if(Input.GetButtonDown("Jump")){
animation["fps_jump"].speed = 0.5;
transform.position += transform.up * jumpSpeed * Time.deltaTime * 15;
animation.Play("fps_jump");
}
transform.Rotate(0, Input.GetAxis ("Mouse X") * rotateSpeed, 0);
}
//rotate around y - axis
function OnCollisionEnter(col : Collision){
if(col.gameObject.tag == "missleP2"){
Health -=10;
}
if(col.gameObject.name == "LavaPlatform"){
Debug.Log("You Are Now Dead");
Health -=100;
}
if(col.gameObject.name == "fallout"){
Debug.Log("You Are Now Dead");
Health -=100;
}
}
function OnGUI(){
GUI.Label(Rect(1890,15,200,100), Health.ToString());
}
function Respawn(){
Health = 100;
transform.position = GameObject.Find("spawn1").transform.position;
}
Thanks in advance!
I would guess your characters pivot is not in the middle. $$anonymous$$aybe try rotating around the character's mesh's center. i.e. Renderer.bounds.center
Okay thank You alot. One question though is how would I go about rotating my character with that?
Answer by robertbu · Mar 21, 2013 at 06:12 PM
As @brainruggieri suggests, your pivot is likely in the wrong place. Possible fixes:
Reset the center in your modeling program
Use the script SetPivot script to reset the pivot.
Use an empty game object as the pivot. You can then either use Transform.RotateAround() to do the rotation, or make the character a child of the empty game object and rotate the empty game object.
Use Transform.RotateAround() and Renderer.bounds.center as @brianruggieri suggests.
Your answer
![](https://koobas.hobune.stream/wayback/20220613094808im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Character Controller rotate unity 1 Answer
Character Axes Rotation Problem 3 Answers
Rotate cube in two direction not working 1 Answer
How to lock Y Rotation 3 Answers
2D : Rotation of Object With x-y Axis 2 Answers