george68 Posted February 16, 2016 Share Posted February 16, 2016 Hi, I need a function that rotates an entity in order to turn and look at another one. So far I have calculated the vector from the source to the destination entity but I don't know how to calculate the pitch, yaw and the roll of the vector. Any assistance will be appreciated. Quote Link to comment Share on other sites More sharing options...
Brutile Posted February 16, 2016 Share Posted February 16, 2016 You could always just use this http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entitypoint-r167 Quote Link to comment Share on other sites More sharing options...
george68 Posted February 16, 2016 Author Share Posted February 16, 2016 Thanks. This is what I was looking for. But I still want to implement a custom function because I want the transition take place smoothly. Quote Link to comment Share on other sites More sharing options...
Einlander Posted February 16, 2016 Share Posted February 16, 2016 This is what I found when I was programming something. it also has resources and sources I used linked function Script:LookAt(start,target) --http://www.leadwerks.com/werkspace/topic/10191-short-example-of-mathatan2/page__hl__lookat --http://stackoverflow.com/questions/1251828/calculate-rotations-to-look-at-a-3d-point --http://leadwerks.wikidot.com/wiki:face-entity --// Calculate angle from point A towards point B local tv = (target - start) local tRoty = Math:ATan2(tv.x, tv.z) --local tRotx = if tv.z >= 0 then tRotx = -Math:ATan2(tv.y* Math:Cos(tRoty), tv.z) else tRotx = Math:ATan2(tv.y* Math:Cos(tRoty), -tv.z) end tRotz = Math:ATan2( Math:Cos(tRotx), Math:Sin(tRotx) * Math:Sin(tRoty) ) return Vec3(tRotx,tRoty,tRotz-90) end Quote Link to comment Share on other sites More sharing options...
Brutile Posted February 16, 2016 Share Posted February 16, 2016 Parameters entity: the target entity to point towards. axis: the entity's axis to orient. This may be 0, 1, or 2, for the X, Y, and Z axes, respectively. rate: a multiplier to indicate how quickly the entity should orient itself. roll: the rotation around the specified axis. Quote Link to comment Share on other sites More sharing options...
george68 Posted February 16, 2016 Author Share Posted February 16, 2016 @Einlander: Thanks. I'll take a look at your snipped. @Brutile: I missed this parameter. I suppose that I have to call this function from within the update loop and call 3 times (one for each axis) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.