Gun made from ray casting isn't working properly

But what do I use now? Do you know what to use?

1 Like

Use Ray.Unit beacuse you already created a Ray.
Read about it here.

What do you mean ray.Unit? I’m not sure what you mean

Read the article I shared in the message above. :+1:

Uhh bro there’s no link in the message you sent above.

Now I see. thanks for telling me that I should use Unit.

Np. Have a good day :+1: (30 chars)

Does the unit have LookVector? I think so

1 Like

No. It does not have a LookVector.

Oh, well, this is the code I wrote for now.

game.ReplicatedStorage.Shoot.OnServerEvent:Connect(function(Player, bulletstart, MousePos)
	local ray = Ray.new(bulletstart.Position, (MousePos - bulletstart.Position).Unit)
	local hit, pos = game.Workspace:FindPartOnRay(ray , nil)
	
	local bullet = game.ServerStorage.Bullet:Clone()
	bullet.Parent = game.Workspace
	bullet.Position = pos
	print(pos)
	
	
end)

Not working

You can not define the Ray as Ray.Unit, define the Ray as a normal Ray and then later when you create the BodyVelocity set the Velocity to be equal to Ray.Unit

You mean local Ray = Ray.new()

No, for instance:

local ray = Ray.new(Vector3.new(0, 5, 0), Vector3.new(0, 15, 0))

Will my code look like this? local ray = Ray.new(bulletStart.Position, (bulletStart.Position - mouse.Hit.p).Unit)

You define a Ray Unit there. Define a normal ray, as you did before.

Use .Touched event, or make a custom ray-casting using decrease basing on part velocity

Oh, so normal ray you mean. Like this? local ray = Ray.new(Vector3.new(0,5,0), Vector3.new(0,15,0))

Yes. (30 characters limit message)

What do I do after it? I don’t know what to do.