Direction Arrow Welded to HRP

To help guide players to their next objective when doing missions, I am welding an arrow to the HPR, then trying to rotate it to point in the required direction by manpulating C1:

-- Weld
	local weld= Instance.new("Weld")
	weld.Part0 = hrp 
	weld.Part1 = arrow
	weld.Parent = hrp
	weld.C0 = hrp.CFrame
	weld.C1 = hrp.CFrame + Vector3.new(0, 0, 5) -- position arrow in front of player

while true do   -- this will be changed to RunService.Heartbeat, using 1 sec update interval allows me to see what is happening
	local hyp = math.sqrt((arrow.Position.X - lookAtPart.Position.X)^2 + (arrow.Position.Z - lookAtPart.Position.Z)^2) -- hypotenuse 
	local sad = arrow.Position.X - lookAtPart.Position.X -- side
	local angle = math.asin(sad/hyp) -- angle option 1
	angle = math.deg(angle)
	print(angle)
	weld.C1 *= CFrame.Angles(0, angle, 0)
	task.wait(1)
end

What I expected was for C1 to simply rotate. the arrow The print(angle) seems to be printing logical angle information. However, the actual outcome is for the arrow to randomly change position around the player.

I know I could use a Beam, but already use them for other in game functions, so don’t want to double up and get confusing.

Any help with where I am going wrong would be appreciated.

Not sure what it looks like right now, but try using math.acos. Also CFrame.Angles takes radians, so try doing math.rad instead of deg.

Is your game in first person? Why weld the part when you can just move it towards the objective.

The game is not in first person. Not sure what you mean " move it towards the objective". Do you mean just anchor it n the workspace and then just lerp it’s CFrame in front of the character?

math.acos has stopped the arrow orbiting around the player… It does however still cotate on it’s axis even when staionary. I assume I am adding the CFrame.Angl;e to the welds current CFrame and not just updating/replacing the value.

I meant you could just put it 5 studs from the character towards the objective or something like that. I asked if it was in first person because you wanted I thought you were welding it in front of the character.

If the angle it’s printing is correct, then you should set
weld.C1 = CFrame.new(weld.C1.Position)*CFrame.Angles(0, angle, 0)

This ended up being the best idea. Not sure why I wanted to weld it to the character. So in the end I just spawn the arrow in front of the character as an Anchored part then rotate using CFrame.lookAt

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.