Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to rotate but not position using cframe?

Asked by 3 years ago

So this code rotates the player to where the mouse clicked, it works perfectly but when I click while moving it moves the player back a bit and I want that to stop. So what I'm asking is how to remove the positioning and only rotate (or a counter to the moving back)

player.Character.HumanoidRootPart.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position, mousehitpos) -- mousehitpos is mouse.Hit.p
0
You could try to use CFrame.lookAt() to turn your character to face your mouse without moving you backwards RazzyPlayz 497 — 3y
0
^ You'll want to replace the Y axis with your HumanoidRootPart's, though Ziffixture 6913 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Hi you should use CFrame.Angles and math.rad.

read about rotationg objects using CFrame.Angles here:

https://developer.roblox.com/en-us/articles/Understanding-CFrame

an example code for using CFrame.Angles is:

local part = game.workspace.Part

targetframe = CFrame.Angles(0, math.rad(10),0)

part.CFrame = tragetframe

Notice how i used math.rad instead of just inserting an angle. This is because CFrame numbers dont work in the way you would expect (for some reason) so you could use math.rad if you want to refer to actual angles!

Hope this wasn't too confusing!

Any questions? Just ask!

0
Radians are the SI unit for measuring angles. 'math.rad' simply converts degrees into radian form Ziffixture 6913 — 3y
0
how would I do this but using a position GameStealerKid 79 — 3y
Ad

Answer this question