RinkyD1nk
(Dev404)
January 11, 2025, 4:22am
#1
So I made a harpoon gun and I wanted to try to make it look like it came from the player.
Example of what’s happening:
Code:
local PlayerClicked = game.ReplicatedStorage.PlayerClicked
PlayerClicked.OnServerEvent:Connect(function(Player, PMH)
local RayOrigin = Player.Character.HumanoidRootPart.Position
local rayDirection = (PMH - RayOrigin).Unit * 500
local raycastResult = workspace:Raycast(RayOrigin, rayDirection)
if raycastResult.Material.Name == "Concrete" then
local Harpoon = Instance.new("Part")
Harpoon.Position = raycastResult.Position
Harpoon.BrickColor = BrickColor.new("Smoky grey")
Harpoon.Size = Vector3.new(4,0.2,0.2)
Harpoon.Anchored = true
Harpoon.Parent = game.Workspace
Harpoon.Shape = "Cylinder"
else
print("CLANG")
end
end)
ninjego1
(ninjego1)
January 11, 2025, 4:52am
#2
You can would change the lookAt property in the Harpoons CFrame
local Harpoon = Instance.new(Part)
Harpoon.Position = raycastResult.Position
Harpoon.BrickColor = BrickColor.new(Smoky grey)
Harpoon.Size = Vector3.new(4,0.2,0.2)
Harpoon.Anchored = true|
Harpoon.Parent = game.Workspace
Harpoon.Shape = "Cylinder"
-- Added Code
local direction = (RayOrigin - Harpoon.Position).unit
Harpoon.CFrame = CFrame.new(Harpoon.Position, Harpoon.Position + direction)
If it’s not rotated on the correct axis you can change it by doing this:
local direction = (RayOrigin - Harpoon.Position).unit
-- Adding a minus on direction.Z will invert that axis
local rotatedDirection = Vector3.new(-direction.Z, direction.Y, direction.X)
Harpoon.CFrame = CFrame.new(Harpoon.Position, Harpoon.Position + rotatedDirection)
1 Like
RinkyD1nk
(Dev404)
January 11, 2025, 5:53am
#3
Works great! but is there some way to make it rotate towards you on the y axis too?
3Xp01tME
(Sparsrsa)
January 11, 2025, 12:55pm
#4
i think making the y axis of the harpoon the same of the player will work