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

Raycast Problem. Its Casting Ray wherever character looks.but why not to weapon's direction?

Asked by 4 years ago
Edited 4 years ago

When call raycast method, it casts ray wherever character looking. Character's right hand is able to follow cursor so im trying to cast ray based on weapon direction. Without sending mouse information to server. there are 2 parts on the weapon which is lined properly. i am using back and front part on the weapon to give direction to ray instead of mouse since weapon can move freely. but it keep casting ray only character's direction. Not the Weapon's direction

function module.castRay(player)
     ray = Ray.new(player.Character.Weapon.BackPart.Position, (player.Character.Weapon.Part.Position - player.Character.Weapon.BackPart.Position).Unit  * player.Character.Weapon.Weapon.Range.Value)
    local part, position = game.Workspace:FindPartOnRay(ray, player.Character, false, true)


    local beam = Instance.new("Part", workspace)
    beam.BrickColor = BrickColor.new("Bright red")
    beam.FormFactor = "Custom"
    beam.Material = "Neon"
    beam.Transparency = 0.25
    beam.Anchored = true
    beam.Locked = true
    beam.CanCollide = false

    local distance = (player.Character.Weapon.Part.Position - position).magnitude
    beam.Size = Vector3.new(0.3, 0.3, distance)
    beam.CFrame = CFrame.new(player.Character.Weapon.Part.Position, position) * CFrame.new(0, 0, -distance / 2)

    game:GetService("Debris"):AddItem(beam, 0.1)


    return part

end

Answer this question