Hey Folks
I still got a problem with my code. Somewhat the rotation doesn’t happen.
Could you have a look over it?
// the player
var object1 : GameObject;
// the object that is supposed to rotate the player
var object2 : GameObject;
// to alter the distance between the object and the player
var newDistance : float = 0.25;
function Update () {
// rotate around the player (?)
transform.RotateAround ((Vector3.zero),(Vector3.up), -80 * Time.deltaTime);
// updating the position of the player
object2.transform.position = (object2.transform.position - object1.transform.position).normalized * newDistance + object1.transform.position;
}
Cheers!
Dawnreaver
Your script rotates the object it’s attached to, then repositions Object2 to be newDistance units away from Object1.
You’ll need to parent object2 to the scripted object, probably.
That didn’t realy resolve the problem
well, i got some fun by writting this script for u,
put this code on any object that u want to turn , then set your entries.
var turnArround : GameObject;
var radius : float = 1;
var speed: float = 100;
var inverseSens : boolean = false;
private var ang : float = 0.0;
function Start(){ if (turnArround) turn_arround(ang) ; }
function Update(){
if (turnArround)
{
turn_arround(ang);
ang += speed * Mathf.Deg2Rad *(inverseSens? -1 : 1) ;
}
}
function turn_arround(alpha){
transform.position.x = turnArround.transform.position.x + radius * Mathf.Cos(alpha * Mathf.Deg2Rad);
transform.position.z = turnArround.transform.position.z + radius * Mathf.Sin(alpha * Mathf.Deg2Rad);
transform.position.y = turnArround.transform.position.y;
}
anon_27031395:
well, i got some fun by writting this script for u,
put this code on any object that u want to turn , then set your entries.
Dude! You are my hero! Awesome!
Thank you very much!!!
np dude, Well i got more fun and i pushed it forward ,
now u can choose the Axe that ur object should turn arround .
var turnArround : GameObject;
var radius : float = 1;
var speed: float = 100;
enum turnArroundAxe { arroundX = 0, arroundY = 1 , arroundZ = 2};
var myAxe : turnArroundAxe = turnArroundAxe.arroundY;
var inverseSens : boolean = false;
private var ang : float = 0.0;
function Start(){ if (turnArround) turn_arround(ang) ; }
function Update(){
if (turnArround)
{
turn_arround(ang);
ang += speed * Mathf.Deg2Rad *(inverseSens? -1 : 1) ;
}
}
function turn_arround(alpha){
alpha *= Mathf.Deg2Rad;
var vxc = (myAxe==0)? 0 : 1;
var vxs = 0;
var vzc = (myAxe==0)? 1 : 0;
var vzs = (myAxe == 0 || myAxe == 2)? 0 : 1;
var vyc = 0;
var vys = (myAxe == 0 || myAxe == 2)? 1: 0;
transform.position.x = turnArround.transform.position.x + radius * (Mathf.Cos(alpha)*vxc + Mathf.Sin(alpha)*vxs);
transform.position.z = turnArround.transform.position.z + radius * (Mathf.Cos(alpha)*vzc + Mathf.Sin(alpha)*vzs);
transform.position.y = turnArround.transform.position.y + radius * (Mathf.Cos(alpha)*vyc + Mathf.Sin(alpha)*vys);
}