x


Vector Alignment and Spacing

I have a vector3 I created from an object that the player can rotate around without rotating the object. I have a second gameobject that I would like its Vector.up constantly looking down the first objects rotatable created vector. So basically i want to be able to rotate my created vector around acting like an arm for the second object, while the second objects up is constantly facing the first. Thanks.

alt text

vecdrawing.jpg (31.9 kB)
more ▼

asked Sep 08 '12 at 04:44 AM

alfredwhitaker15 gravatar image

alfredwhitaker15
18 2 2

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

1 answer: sort voted first

Supposing that the script is attached to the first object, drag the second object to the field satellite in the script below:

var vector: Vector3; your rotatable vector
var satellite: Transform; drag the second object here

function Update(){
  // move satellite to the vector tip:
  satellite.position = transform.position + vector;
  // orient up side of satellite to the first object:
  satellite.rotation = Quaternion.FromToRotation(Vector3.up, -vector);
}
more ▼

answered Sep 08 '12 at 05:47 AM

aldonaletto gravatar image

aldonaletto
41.3k 16 42 195

It worked perfectly, is there any way to align the satellites z-axis so that its always looking the same direction of the origins z-axis and still have the same functionality?

Sep 08 '12 at 06:12 AM alfredwhitaker15

let Aldo have a sleep-in, for God's sake! :)

I believe the LookAt function may solve what you further ask .. check the doco.

Sep 08 '12 at 06:38 AM Fattie

I used the LootAt function and tried to restrict it to look down the zaxis of the origin gameobject which works, until I begin to rotate my satellite around it and then its zaxis just kinda floats in any direction it wants, not being restrained to the origins axis, Any help would be appreciated. Thanks

Sep 08 '12 at 04:43 PM alfredwhitaker15

I don't know if I correctly understood what you wanna do, but suppose that you could try the following:

function Update(){
  // move satellite to the vector tip:
  satellite.position = transform.position + vector;
  // orient satellite's Z and Y axes:
  satellite.LookAt(satellite.position + Vector3.forward, -vector);
}

According to the docs, this should make the satellite forward axis parallel to the world Z axis, while keeping its up side turned to the first object - but I don't bet my life on this, since LookAt(position, upDirection) has disappointed me a couple of times in the past.

Sep 09 '12 at 03:35 AM aldonaletto
(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:

x2156
x327
x101
x29

asked: Sep 08 '12 at 04:44 AM

Seen: 358 times

Last Updated: Sep 09 '12 at 03:36 AM