Jump to content

SetRotation() snapping back to original


Rick
 Share

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...