-
What do you want to achieve?
The ray without an obstacle in its way appears to simulate bullet drop correctly, however when given an obstacle in front of it, it goes straight without any drop
The object that is ray casting is that Y 30, and when given an obstacle the part spawned to visualize the area hit is also at Y 30
-
What is the issue?
The red line in the 2nd image is where the ray actually goes, with the green curved line being the intended and actual direction of ray when not met with an obstacle
-
What solutions have you tried so far?
I have tried 2 things, those being that - Attempted to place portion of code below above the actual raycasting line, however that only puts the raycast in a downward angle instead of simulating bullet drop
bulletVelocity = bulletVelocity - (Vector3.new(0, workspace.Gravity, 0) * dt)
bulletPos = bulletPos + bulletVelocity * dt
- Lessened the MuzzleVelocity variable, which made some changes but I’d like the ray to go far beyond 500 studs
local MuzzleVelocity = 2329
local RayOrigin = script.Parent.Position
local RayDirection = script.Parent.CFrame.LookVector*MuzzleVelocity
local RunS = game:GetService("RunService")
local function fireBullet()
local bulletPos = RayOrigin
local bulletVelocity = RayDirection
local dt = RunS.Stepped:Wait()
local RayStepped
RayStepped = RunS.Stepped:Connect(function()
local bulletCast = workspace:Raycast(bulletPos, bulletVelocity)
if bulletCast then
print(bulletCast.Instance, bulletCast.Position, bulletCast.Normal)
RayStepped:Disconnect()
local Landedpart = Instance.new("Part")
Landedpart.Parent = workspace
Landedpart.Anchored = true
Landedpart.Position = bulletCast.Position
Landedpart.Size = Vector3.new(5, 5, 5)
Landedpart.Material = Enum.Material.Neon
Landedpart.BrickColor = BrickColor.new("Bright red")
else
bulletVelocity = bulletVelocity - (Vector3.new(0, workspace.Gravity, 0) * dt)
bulletPos = bulletPos + bulletVelocity * dt
print(bulletVelocity.Magnitude)
local DebugPart = Instance.new("Part")
DebugPart.Parent = workspace
DebugPart.Anchored = true
DebugPart.Position = bulletPos
DebugPart.Size = Vector3.new(5, 5, 5)
DebugPart.Material = Enum.Material.Neon
DebugPart.BrickColor = BrickColor.new("Bright red")
if bulletVelocity.Magnitude >= 2500 then
print("STOP")
RayStepped:Disconnect()
end
end
end)
end
fireBullet()
Fyi this is modified code as I’m learning raycasting currently