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

Is There a better way to do this? (Raycasting)

Asked by 8 years ago

I made a raycast gun, it works, except for one thing. The laserShotClone is supposed to hit a wall before falling, but instead if there is a wall 1000 or less studs ahead of the handle, the laserShotClone just falls right when it is shot. I want to make it only fall if it hits a wall, but I'm not a raycast master. Help?

local laserShotClone = BaseShot:Clone()
    laserShotClone.CFrame = shotCFrame + (shotCFrame.lookVector * (BaseShot.Size.Z / 2))
    local bodyVelocity = Instance.new('BodyVelocity')
    bodyVelocity.velocity = shotCFrame.lookVector * SHOT_SPEED
    bodyVelocity.Parent = laserShotClone
    local GunRay = Ray.new(script.Parent.Handle.Position, (shotCFrame * CFrame.new  (0,0,-1000)).p - script.Parent.Handle.Position)
    local Hit, Pos = game.Workspace:FindPartOnRay(GunRay, script.Parent.Parent:FindFirstChild   ("Character"))
    if Hit then 
    laserShotClone:FindFirstChild("BodyVelocity"):Destroy()
    end
    laserShotClone.Touched:connect(function(otherPart)
        OnTouched(laserShotClone, otherPart)

Answer this question