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!
Still having the problem, Anyone?
– uberokeerI would guess your characters pivot is not in the middle. Maybe try rotating around the character's mesh's center. i.e. [Renderer.bounds.center][1] [1]: http://docs.unity3d.com/Documentation/ScriptReference/Renderer-bounds.html
– roojerryOkay thank You alot. One question though is how would I go about rotating my character with that?
– uberokeer