I’m recreating a pixel dungeon or Pokémon mystery dungeon game, specifically the dungeon tile based movement mechanic. And I’m struggling with rotating the model to face the direction the player is moving.
How would I go about this?
I’m recreating a pixel dungeon or Pokémon mystery dungeon game, specifically the dungeon tile based movement mechanic. And I’m struggling with rotating the model to face the direction the player is moving.
How would I go about this?
You can use CFrame.lookAt() to move the entire model to face a part, which in this case is the player’s HumanoidRootPart.
You can use this script to make the model constantly face a player, as long as the model has a PrimaryPart.
local model = script.Parent
local playerToLookAt = -- put whatever player you want it to look at here
game:GetService("RunService").Heartbeat:Connect(function()
model:PivotTo(CFrame.lookAt(model.PrimaryPart.Position, playerToLookAt.HumanoidRootPart.Position))
end)
This works for the most part, but I’ve found that because I’m using a tween to move the playerModel to the next tile, the turn eventually corrects itself back to the direction it was originally facing. How could I counter that?
If you don’t need the model to constantly look at the player’s character, you could have the model face the player upon the tween’s completion by running the model:PivotTo() line that I sent in the earlier post upon the tween:Completed event firing.
However, if the model needs to constantly look at the player, even during tweens, you could replace the tween with a lerp, and then inside the lerp have the model face the player as well.
sorry for the late response btw
Just got back from a trip, but I also just tried this out and this worked! Thanks a million man!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.