Rick Posted September 23, 2014 Share Posted September 23, 2014 So in my HGT2 game when I attack an enemy I have the player (character controller) turn and face the player. This worked at one point but now it turns for that frame only, then the next frame it goes back to the old rotation. MoveAndCheck Inside Attack Inside ForEach Orc hit Facing mob 28.791143417358 -- after facing the mob 4 Y rotation = 28.791143417358 -- same frame but the last line in UpdateWorld() 1 Y rotation = 99.609992980957 -- the next frame and the first line in UpdateWorld() I can't figure out why it's getting reset back to 99 (in this case) and not staying at 28 (in this case). Any ideas? Here is the FaceMob() function where I pass in the location of the enemy and as the log (and visual) shows it does do it's job but only for that frame before it's getting reset. function Script:FaceMob(pos2) local pos1 = self.entity:GetPosition(true) local v = Vec2() v.y = pos1.x - pos2.x v.x = pos1.z - pos2.z local angle = Math:ATan2(v.y, v.x) self.entity:SetRotation(0, angle, 0) System:Print("Facing mob "..angle) end Quote Link to comment Share on other sites More sharing options...
Crazycarpet Posted September 24, 2014 Share Posted September 24, 2014 Would Entity::Point not do this..? Quote Link to comment Share on other sites More sharing options...
shadmar Posted September 24, 2014 Share Posted September 24, 2014 Entity:Point() works ok for this I'd think too. Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Rick Posted September 24, 2014 Author Share Posted September 24, 2014 I never seem to have any luck with that but will give it a shot. Quote Link to comment Share on other sites More sharing options...
Crazycarpet Posted September 24, 2014 Share Posted September 24, 2014 Alright, let us know how it goes if it still isn't working properly I'll try to mimic the issue after work, best of luck to you! Now, I'm new to Leadwerks and I don't know how many of these functions work, but I'd assume its possible that SetRotation doesn't work on Character Controlled entities and maybe the player's camera would play a role in resetting your rotation, this is why I feel Entity::Point would be better; however as I said these functions I haven't yet tried and this is just a prediction. That being said if it worked before the most likely alternative is that another piece of script, something you wrote recently that also manipulates the player's rotation is interfering. 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.