What do you want to achieve?
Whenever I use a spell, I want to rotate the character towards the target. This part is done.
What is the issue?
However, if the character is moving right before casting the spell, they get teleported a couple of studs in some direction, which looks weird.
EDIT: The character seems to teleport to where they stood a split second before.
What solutions have you tried so far?
I have not managed to find any solution. It would be ideal if there was any way to only rotate a model without moving it.
Thanks in advance!
local playerCharacterCFrame = CFrame.new(playerCharacter.Hitbox.Position, playerTargetModel.HumanoidRootPart.Position)
playerCharacter:SetPrimaryPartCFrame(playerCharacterCFrame)
What’s occurring is natural: Lua is recording the CFrame moments before it updates the CFrame of the character. In other words, it’s lag.
You can fix this by stopping the character. This way, the recorded position will be the same as the position applied. Assuming playerCharacter has a Humanoid, write the code below in the exact same order.
local lastSpeed = playerCharacter.Humanoid.WalkSpeed
playerCharacter.Humanoid.WalkSpeed = 0
local playerCharacterCFrame = CFrame.new(playerCharacter.Hitbox.Position, playerTargetModel.HumanoidRootPart.Position)
playerCharacter:SetPrimaryPartCFrame(playerCharacterCFrame)
playerCharacter.Humanoid.WalkSpeed = lastSpeed
--Cast spell here. This is your part.
If you don’t like the stopping effect, I’d suggest swapping the last two lines of code, but that only applies if the character shouldn’t be allowed to move when casting spells.
Hope you find this helpful.
The thing is, I was already setting the speed to 0 before defining the position. I will simply have to add in some 0.2 seconds of wait, which works well now that I tested it. Thanks!