Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i properly make my spear aim?

Asked by 2 years ago

im basically making gae bolg (a spear weapon that u throw) from fate and i have a little problem the spear goes to the direction of the mouse but idrk how to make it properly aimable

heres the video (medal clip)

https://medal.tv/games/roblox-studio/clips/AicE2aNe26JmO/d1337ohMSeCh?invite=cr-MSxGb24sNjU0MzQwMDEs

heres the part of the script where i have the aiming system basically


GEvent.OnServerEvent:Connect(function(Player,mouseaim) local Character = Player.Character local Humanoid = Character.Humanoid local Root = Character.HumanoidRootPart local GaeBolgThrown = game.ReplicatedStorage.Objects.GaeBolgThrown:Clone() GaeBolgThrown.CFrame = Tool.Handle.CFrame * CFrame.new(0,0,0) GaeBolgThrown.Orientation = GaeBolgThrown.Orientation + Vector3.new(0,0,0) GaeBolgThrown.Parent = workspace local RootPos, MousePos = Root.Position, mouseaim Root.CFrame = CFrame.new(RootPos, Vector3.new(MousePos.X, RootPos.Y, MousePos.Z)) local BV2 = Instance.new("BodyVelocity",GaeBolgThrown) BV2.MaxForce = Vector3.new(math.huge,math.huge,math.huge) BV2.Velocity = CFrame.new(Character.HumanoidRootPart.Position,mouseaim).LookVector*400 end)

1 answer

Log in to vote
0
Answered by 2 years ago

I don't know what the mouseaim is, but when sending the mouseaim to the server, I recommend using Camera:ViewportPointToRay since it accurately gets its position in the workspace by making a unit Ray, and it ignores the GuiInset at the top of the screen.

-- Client

local depth = 0 -- optional; 0 by default
local length = 1 -- optional; 1 by by default

local unitRay = Camera:ViewportPointToRay(Mouse.X, Mouse.Y, depth) -- converting the mouse position to a ray by using its X and Y axis, and the depth variable

GEvent:FireServer(unitRay.Direction * length) -- sending unitRay's direction or lookVector to the server
-- Server

GEvent.OnServerEvent:Connect(function(Player,mouseaim)

    local Character = Player.Character
    local Humanoid = Character.Humanoid
    local Root = Character.HumanoidRootPart


    local GaeBolgThrown = game.ReplicatedStorage.Objects.GaeBolgThrown:Clone()
    GaeBolgThrown.CFrame = Tool.Handle.CFrame * CFrame.new(0,0,0)
    GaeBolgThrown.Orientation = GaeBolgThrown.Orientation + Vector3.new(0,0,0) 
    GaeBolgThrown.Parent = workspace

    Root.CFrame = CFrame.new(Root.Position, mouseaim)


    local BV2 = Instance.new("BodyVelocity",GaeBolgThrown)
    BV2.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
    BV2.Velocity = CFrame.new(Character.HumanoidRootPart.Position,mouseaim).LookVector*400


end)

If there is still a problem with the mouse aim, I recommend editing the depth and/or length variable from the client.

Ad

Answer this question