Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can i rotate an object properly using the information from Mouse.Hit?

So, i'm trying to rotate a fairly basic object to always face the mouse when fired, however nothing i tried seems to work, i would really appreciate some help with this, this is the closest i've been able to get to what i need. Here's the code involved:

local function getPitch(vec)
		
		return math.asin(vec.y) - math.pi/2
		
	end
	
	local function getYaw(vec)
		
		return math.asin(vec.x) + math.pi/2
		
	end
	
	
	local pitch = getPitch(hit.LookVector)
local yaw = getYaw(hit.LookVector)
	
	
	trident.CFrame = hrp.CFrame * CFrame.new(0,5,0) * CFrame.Angles(pitch,yaw,math.rad(90))

1 answer

The issue was that you where running trident.CFrame = hrp.CFrame * CFrame.new(0,5,0) * CFrame.Angles(pitch,yaw,math.rad(90)) only once, now it should repeat.

local function getPitch(vec)

        return math.asin(vec.y) - math.pi/2

    end

    local function getYaw(vec)

        return math.asin(vec.x) + math.pi/2

    end

while true do
wait()
local pitch = getPitch(hit.LookVector)
local yaw = getYaw(hit.LookVector)

trident.CFrame = hrp.CFrame * CFrame.new(0,5,0) * CFrame.Angles(pitch,yaw,math.rad(90))
end

This discussion is preserved as it was. New answers, comments, and votes are closed.