- Home /
transform.position on basis of rotation
hi, i need change position of object always on same length on basis of rotation. somethink like transform.position = Vector3(0,20,0); ,i try look on google but i dont see enythink what can help me. thx
You need to provide significantly more information before someone can give you a targeted solution. A drawing would be very helpful. If I read between the lines and guess a bit, what you need to do is:
Create an empty game object and place it at the pivot point of your rotation.
Position your visible object at "same length' away from the pivot point.
$$anonymous$$ake the visible object a child of the empty game object.
Use whatever code to rotate the empty game object. You can set the transform.eulerAngles of the empty game object.
There are other solutions like Transform.RotateAround() and using a Quaternion to rotate a vector and then using the vector to position the object. This is all guesswork on my part.
yes sory i try it explain... i create animation enythink how dust around my starship in space, when i go front it work good it going from up to down and again but when i rotate my ship(player) it still transform to same direction not front of my ship. here is script:
#pragma strict
var animator : Animator;
static var speed = 0;
var mypos : Transform;
var playerpos : Transform;
var maxdist = 20;
var newpos : Vector3;
function Start () {
animator = GetComponent("Animator");
}
function Update () {
if(speed > 30) {
animator.SetBool("start",false);
}
else {
animator.SetBool("start",true);
}
newpos = mypos.position + Vector3(0,50,0);
var newspeed = speed * (-1);
mypos.transform.rotation = playerpos.rotation;
rigidbody2D.velocity = transform.up * newspeed * Time.deltaTime;
}
function OnTriggerExit2D(col : Collider2D){
if (col.gameObject.tag == "PrachSpawner") {
mypos.transform.position = newpos;
}
}
it still not done i only try how it work.