BodyPosition moving to wrong location?

I’m trying to make a dunk key bind using BodyPosition, however, my player always goes to the left side of the rim as shown:
image

I’ve tried switching the goal variable to a part at the centre of the hoop but this has yielded no results.

function rotateToHoop()
	local hoop = GetGoal()
	local goal = hoop.green
	local bg = Instance.new("BodyGyro", Root)
			bg.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
			bg.P = 25000
			spawn(function()
				bg.CFrame = CFrame.new(plr.Character.HumanoidRootPart.Position, Vector3.new(goal.Position.X, plr.Character.HumanoidRootPart.Position.Y, goal.Position.Z)) 
				wait (.5)
				bg:Destroy()
			end)
end

local function gotoHoop()	
	local hoop = GetGoal()
	local goal = hoop.green
	local bodyPos = Instance.new("BodyPosition", Root)
    	bodyPos.D = 1100
	    bodyPos.P = 9000
	spawn(function()
			bodyPos.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		    bodyPos.Position = goal.Position - Root.CFrame.LookVector * 1.8
		wait(1.1)
		    bodyPos:Destroy()
    end)
end	

This is how I structure my code, is there any way of solving this issue?

Thanks in advance!
-SpaceHex-

1 Like

Personally, I would use an animation for these types of things because body movers on characters can always cause problems.

However in your case, I assume you execute the functions directly after eachother, in which case the character will not have rotated before you index Root.CFrame.LookVector. An easier solution to create an offset is just to calculate it based on the position of both the hoop and the player.

bodyPos.Position = (CFrame.new(goal.Position, Vector3.new(Root.Position.X, goal.Position.Y, Root.Position.Z)) * CFrame.new(0, 0, -3)).p

3 being the goal distance between character and hoop.

1 Like

Ah, the reason I don’t use animations is that I tried previously but I couldn’t quite get them to work, but this worked!
How can I get the player to move slightly closer to the goal though even though all else is perfect!

1 Like
CFrame.new(0, 0, -3)

Change the 3 to a smaller number to reduce the distance, so e.g. CFrame.new(0, 0, -1.5)

2 Likes