Notifications
Clear all

[Closed] Scripted rotation look-at controller?

I don’t have a firm grasp of quaternion math so I was wondering if anyone could help me with scripting a look-at controller?

I tried implementing this solution:

http://joleanes.com/tutorials/flippingless/flippingless_02.php

But I can’t seem to get it to work right with anything other than bones that are parented to other bones.

I know I need to get a vector between the rotating object and the target, etc…I just don’t know how to translate that data into a correct rotation. Ideally I’d like to find a solution that is flexible enough to favor parent-space of the rotating object, but would default to world space if no parent exists.

Any help would be appreciated!

11 Replies

A very useful and needed controller in max.

1 Reply
(@ivanisavich)
Joined: 1 year ago

Posts: 0

Sarcasm detected :)…I know about the built-in lookat controller, but it won’t work for what I’m doing. That’s why I need to make my own.

here is a basic:

delete objects
(
	t = dummy name:"target" pos:[100,0,20]
	s = point name:"source" axistripod:on cross:off box:on pos:[0,0,0] wirecolor:orange

	c = s.rotation.controller = rotation_script()
	c.addnode "target" t
	c.addnode "source" s
	c.setexpression "(arbAxis (normalize (target.pos - source.pos))).rotation"
	/* OR
	c.addobject "pos" s.position.controller
	c.setexpression "(arbAxis (normalize (target.pos - pos.value))).rotation"
	*/
)

but there are many nuances:

specific look-at axis

using UP vector to support both look-at target and target’s spin

not flip solution

etc.

what specific things do you need?

Hmm interesting solution Denis…although I don’t think it’ll work for my problem because I think I’ll manually need to construct the matrix so I can define up vector, etc.

Basically I have hundreds of objects that I want to be affected by a ‘wind’ value. The ‘wind’ value will define an arbitrary point in 3d space towards which all objects will point (look-at) along a specific axis. I’d prefer to do this with script controllers to avoid having to actually create an object at that point in space to which the built-in lookat controller would point. Also there are some other reasons why I’m choosing script controllers that are not important to the solution of this problem.

Anyways, ideally I’d like to make it so that objects look towards that arbitrary position in parent space (to avoid flipping), but if they don’t have a parent they look towards it in world space.

Seems like a simple problem, I just don’t know how exactly to construct the quaternion.

I’m not being sarcastic, It’s very cool what you’ve done here with your moded version.

I like it.

1 Reply
(@ivanisavich)
Joined: 1 year ago

Posts: 0

Oh, oops! Must have been a misunderstanding…I didn’t write the scripted lookat controller in my original post. That was just what I referenced in my attempt to make one.

I thought you were saying ‘a needed controller in max’ facetiously because max already has a look-at controller. That’s why I clarified that the built-in lookat controller isn’t sufficient for me in this case.

So I found out why my original implementation of the script I linked to wasn’t working…it’s because I was adding the script controller to a rotation_list, rather than setting it as the sole controller of the objects I was trying to get to lookat the target properly.

Everything works fine now!

the script controller is very slow in comparison with built-in look-at controller. and it leaks in memory very badly. so using it with hundreds of objects will be very expensive. how is about Particle Flows and Position and Rotation scripts? that’s probably how i would do it.

The reason I can’t use particles is because many of the objects are parented to other objects, which themselves have the lookat controller on them.

How bad do the rotation script controllers leak memory, and are there any steps I should be taking to try and avoid that as much as possible (while still using them)?

1 Reply
(@denist)
Joined: 1 year ago

Posts: 0

that’s ok. the particle flow is a parent for its particles. script has to take it into account

How bad do the rotation script controllers leak memory, and are there any steps I should be taking to try and avoid that as much as possible (while still using them)?

sometimes script controller can leak very badly. i had to re-design some of my rigs just because of that. recommendations… hmm… hard to say. it depends on script itself. one thing for sure is if it’s possible use an expression controller instead of a script controller. but… there is no rotation expression controller in the max… i’ve made in some cases “expression” rotation controllers using three Float_Expressions. but it’s an exotica.