I am not really sure what code I should try, so for now, I am using ToObjectSpace.
The “Y” direction is like this right?
Anyways,
I have A NPC model, that when I press R, it rotates 45 degrees in the (I think) Y Direction. It works nicely on most surfaces, but on uphill surfaces, The NPC rotates On the Y axis (usually good) but then The NPC’s legs, are like this (the green parts are the legs)
function RotNPC ()
local NPC = --patch to NPC model
local currentPivot = --patch to NPC model:GetPivot()
NPC:PivotTo(currentPivot + Vector3.new(0, 0, 45))
end
-- also sript / promt triggered :Connect(RotNPC)
Unfortunately, I’m going to sleep now (it’s almost night time), but the problem is probably that you need to make small invisible ones
like steps on the slope so that the tower can stand flat (It looks like something on TDS)
This is not an ideal version, it is something similar to my idea
You can try to make in your script that the position of NPC Z (or Y) will be constant all the time, which will not allow the NPC to change the angle of inclination
I am teleporting the model to the mouse position/hit every .05 seconds, I want the base (The blue part ) to always be on top, or an even distance to the top. In the video, a second before it ended, you could see all of the base evenly spaced under the grey part. You know when you rotate a model, and Press L to rotate it based on It’s current rotation? How would I get the Grey part’s rotation, and apply it to the NPC’s rotation?
Okay, I got that done, but when I press R a second time the NPC’s Y axis rotates. How to I get the direction the HumanoidRootPart of the NPC is looking at?
local MouseTarget = Mouse.Target
local MouseHit = Mouse.Hit
local Target = Plr.TroopTargetUnfinishedPlacement.Value--The model
--Gets the models orientation, and the value of the wanted to increase rotatation
local TargetX = math.rad(MouseTarget.Orientation.X + Target.XRotation.Value)
local TargetY = math.rad(MouseTarget.Orientation.Y + Target.YRotation.Value)
local TargetZ = math.rad(MouseTarget.Orientation.Z + Target.ZRotation.Value)
local NewPart = Instance.new("Part")
NewPart.Anchored = false
Target.YRotation.Value += IncreaseValueRotationValue
NewPart:PivotTo(CFrame.new(MouseHit.Position) * CFrame.Angles(TargetX,TargetY,TargetZ))
local PartCFrame = NewPart.CFrame
NewPart:Destroy()
CFrame.Angles(TargetX,TargetY,TargetZ) )
Target:PivotTo(PartCFrame)
I was about to post the same thing. Basically, you can raycast downwards from some part by raycasting from part.Position to part.CFrame.UpVector*-5 or something like that. Then, the raycast result table has something called “normal” it just gives you the unit vector that is perpendicular to the ground. You can then use SetPrimaryPartCFrame accordingly on the npc to get it to rotate correctly.
Do you have an example of could I could use? I am still somewhat confused. So I raycast up to the NPC from the part that the NPC is on, then I get a “normal” value?