Java - transform.LookAt while spinning

I’ve got an object that I want to always look at a target but I also want it to constantly rotate around its local Y axis (Think spinning missile moving along a track). I’ve got each of those parameters working individually but when I put them together the LookAt overwrites the Y rotation. Any ideas on how I could achieve this?

Java-SCRIPT. NOT JAVA. Whats wrong with you people???

Use Quaternion.LookRotation() instead and concatenate your Y-axis rotation to it…

var spinAngle:float = 0;
var spinSpeed:float = 45; // 45 degrees per second
function Update()
{
   // look at the target
   var q1:Quaternion = Quaternion.LookRotation(target);  
   // rotate around the Y-axis (or whatever axis you want)             
   var q2:Quaternion = Quaternion.AngleAxis(spinAngle, transform.up); 
   // concatenate the rotations.
   transform.rotation = q1 * q2;                                     
   
   spinAngle += spinSpeed * Time.deltaTime;
}

It’s not their fault. Blame Brendan Eich. :slight_smile:

Also… Unityscript, not Javascript. :wink:

CrazySi:

because java is shorter and since we’re on a unity forum it’s pretty safe to assume that’s what is meant. Sorry to truly inconvenience your day and take up all the time it took for you to write that concise and helpful comment.

Brian:
Thanks loads man.

Hmmm, didn’t work. Ran into the same issue I ran into with other methods: while the object is spinning it’s “LookAt” (or equivalent that you provided) get’s screwed up and causes the object to look in the wrong direction.

Yes it did inconvenience me. Use JS its even shorter OMFG. Its NOT Java.

There’s no point in getting upset. There will literally never (unless armageddon) be a time when someone with a low number of posts calls Unity’s version of Javascript something wrong on a daily basis. It’s just a natural state of the universe, like how night follows day.

Seriously Admin can we block the word “Java” on here if it is not immediately not followed by “script”. These Java trolls are ruining this forum. Can we at least place a sticky explaining the difference between Java and Javascript?

To be honest I’d rather keep the people asking legitimate albeit poorly phrased questions over the people making multiple excessively emotive posts about a trivial issue.

How about answering the question and adding a simple liner like “Also you should be aware that Unity’s scripting language is called javascript not java. Its also commonly referred to as UnityScript to disambiguate it from the javascript used on the web to which it bears only a passing resemblance”.

Trivial? Attitudes like yours breed ignorance…“there there its ok to not bother learning” that attitude makes me sick…I dont’t/won’t/can’t tolerate it. We need to extinguish this attitude. Java is not, repeat NOT Javascipt.

I think I clearly indicated that you should inform people of their mistake: “How about answering the question and adding a simple liner like…”

I’m all for informing people when they make mistake, however making multiple posts about the same issue and making comments like “These Java trolls are ruining this forum” doesn’t foster understanding; it typically lead to pointless argument such as this.

EDIT: It might also be worth noting that many people feel strongly about “incorrectly” calling the language “javascript” when it is not the well known javascript language. Yes Unity Technologies decided to call it this (presumably for marketing reasons), but many posters on this forum have argued that this misinformation shouldn’t be propagated and the language should be referred to as UnityScript (based on the name of the dll).

It is absurd to assume that someone with no programming experience would instantly know that Java is not Javascript.
Absurd.

If someone has three hundred posts asking for help with simple problems in “Java”, and you’ve observed that they have been told multiple times that it is ‘javascript’, then you get upset. Maybe. But certainly not the very first time they ask.

I mean, that’s like me walking into a tool shop and pointing to a cross-head screwdriver and saying I need help using that nail-twister. You chuckle and tell me it’s a screwdriver, no harm done.

Yep I overreacted a bit sorry :slight_smile:
Its something that came up so many times in the past it kind of annoyed me.

Yes it was an overreaction, sometimes it boils over from other similar discussions. And I think thats a good point regarding UnityScript not being Javascript.

Actually on topic for this. I like make a parent/child relationship and use one to look at the point and the other for the rotation.