How to get rotation difference using ToObjectSpace

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?

Could you show the code your using to rotate and position the npc?

When a player presser R-

	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 recommend you to use raycast’s instead as it gives you a normal vector to work with to easily align itself with the part’s surface

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?

Raycast down from the NPC. I need to know the formatting of your npc in order to know the exact thing to raycast from.

I have a R6 blocky npc, on a part that is rotated 45 degrees. I am not sure what else to put.

An explorer screenshot would help a bit. Just basically raycast from the npc’s main body downward at the ground.

Also check this post out, it should help you with aligning the npc.

game.Workspace.NPC.HumanaoidRootPart
game.Workspace.TargetPart

like this?

Uh… Do some research on raycasting.

Like so?
If so, what Is the “Normal” that I get 5% of the time?

local raycastParams = RaycastParams.new()
			local raycastResult = workspace:Raycast(Target.HumanoidRootPart.Position, MouseTarget.CFrame.LookVector * 50, raycastParams)
			if raycastResult then
				print(raycastResult.Normal)
			else
				print("no result")
				end

You want to raycast to Target.HumanoidRootPart.CFrame.UpVector*-50 instead.

like this?

local raycastParams = RaycastParams.new()
			local raycastResult = workspace:Raycast(MouseTarget.Position, Target.HumanoidRootPart.CFrame.UpVector*-50, raycastParams)
			if raycastResult then
				print(raycastResult.Normal)
			else
				print("no result")
				end

no you want to raycast from Target.HumanoidRootPart.Position to Target.HumanoidRootPart.CFrame.UpVector*-50. Try looking up a tutorial on raycasting first.

			local raycastResult = workspace:Raycast(Target.HumanoidRootPart.Position, Target.HumanoidRootPart.CFrame.UpVector*-50, raycastParams)
			if raycastResult then
				print(raycastResult.Normal)
			else
				print("no result")
				end

Yes. Now check the post I linked earlier, it will help you properly set the cframe.

It doesn’t make any sense. I tried editing it, and nothing happened.