Vulcan Posted July 9, 2014 Posted July 9, 2014 Today I got into little problem with how to get a entity to look at a specific point Vec3(x, 1, z). I would suggest updating the Math::ATan2 documentation to include an example of how to do this with both C++ and Lua. I found this explaination usefull. Another suggestion could be to add a method for Entity class. Maybe something like: Entity::LookAtXZ(..) for 2d look at XZ (still usefull for 3d) Entity::LookAtXYZ(..) for 3d look at (ie: a players head looking at something, just like minecraft does) Quote
gamecreator Posted July 9, 2014 Posted July 9, 2014 http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/entity/entitypoint-r167 Quote
Vulcan Posted July 9, 2014 Author Posted July 9, 2014 But what if I need to point it at a Vec3 coordinate? Quote
gamecreator Posted July 9, 2014 Posted July 9, 2014 Put an entity there? Long answer: Create a box at the start of your program. Hide it. Whenever you need to point something at a location: Unhide box Position it to location Point entity at box Hide box Quote
Vulcan Posted July 9, 2014 Author Posted July 9, 2014 Put an entity there? Long answer: Create a box at the start of your program. Hide it. Whenever you need to point something at a location: Unhide box Position it to location Point entity at box Hide box Thats quite a creative solution I must say, but still I think a Entity::LookAt(..) would look cleaner way to do it. This works and I think this is something that LE should have: void LookAt(Vec3 lookAt) { // Calculate angle from point A towards point B Vec3 tv = lookAt - obj->GetPosition(); float tRoty = Math::ATan2(tv.x, tv.z); // Look at point B (height is excluded) obj->SetRotation(Vec3(0.0f, tRoty, 0.0f)); } EDIT: Physics must be set to rigid mode temporary when SetRotation 2 Quote
Haydenmango Posted July 10, 2014 Posted July 10, 2014 I would like an Entity:LookAt() function. Would save me some lines of messy math code. Also you could use SetInput(rot.y) for a character controller instead of switching its physics mode temporarily to use SetRotation(0,rot.y,0). At least I think that should work. Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding
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.