#help with raycasting

27 messages · Page 1 of 1 (latest)

iron depot
#

use raycast params and whitelist the players character only

somber pebble
iron depot
#

wait

somber pebble
#

ye

iron depot
#

this isnt a raycast?

#

workspace:RayCast

somber pebble
#

wdym the code that i got?

iron depot
#

U should always use workspace:Raycast, because Ray.new is deprecated, take a look on the forum

#

local rayOrigin = Vector3.new(0, 0, 0)
local rayDirection = Vector3.new(0, -100, 0)

local raycastResult = workspace:Raycast(rayOrigin, rayDirection)

#

this is how u use raycast

somber pebble
#

i did i get to confused

iron depot
#

?

somber pebble
#

so on the

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local function performRayCast()

local ray = Ray.new(
    player.Character.Head.Position,
    (mouse.Hit.p - player.Character.Head.Position).unit * 100
)

local position = workspace:FindPartOnRay(ray, player.Character)

if player.Character then
    print(player.Name)
end

end

mouse.Button1Down:Connect(performRayCast)

what do i change in this?

iron depot
#
local raycastResult = workspace:Raycast(player.Character.Head.Position,  (mouse.Hit.p - player.Character.Head.Position).unit * 100)
#

like this for u

#

and to see if it hit a part you do

local raycastResult = workspace:Raycast(player.Character.Head.Position,  (mouse.Hit.p - player.Character.Head.Position).unit * 100)

if raycastResult then
  local Hit = raycastResult.Instance
end
long daggerBOT
#

studio** You are now Level 9! **studio

somber pebble
#

so like this

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local function performRayCast()

local ray = workspace:Raycast(
    player.Character.Head.Position,
    (mouse.Hit.p - player.Character.Head.Position).unit * 100
)

local raycastResult = workspace:Raycast(player.Character.Head.Position,  (mouse.Hit.p - player.Character.Head.Position).unit * 100)

if raycastResult then
    local Hit = raycastResult.Instance
end

end

mouse.Button1Down:Connect(performRayCast)

iron depot
#

not ur doing two raycasts remove local ray =

#

keep local raycastresult and below that

somber pebble
# iron depot not ur doing two raycasts remove local ray =

did i do it right?

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local function performRayCast()

local raycastresult = workspace:Raycast(
    player.Character.Head.Position,
    (mouse.Hit.p - player.Character.Head.Position).unit * 100
)

local raycastResult = workspace:Raycast(player.Character.Head.Position,  (mouse.Hit.p - player.Character.Head.Position).unit * 100)

if raycastResult then
    local Hit = raycastResult.Instance
end

end

mouse.Button1Down:Connect(performRayCast)

long daggerBOT
#

studio** You are now Level 5! **studio

iron depot
#

@somber pebble you should watch gnomecode's tutorial on raycasting and check the documentation. when you are ready to learn it it should be intuitive

somber pebble
#

i might check that out