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

How would I go about making a distance delay for a gun using Raycast? [Sorry, no code included]

Asked by 10 years ago

In big FPS's you see things such as Bullet delay, to give you a brief description (If you don't know what it is). Here's an example. One person is walking on the Z axis, and you're looking at them from the X axis, the person is moving from left to right, therefore, due to the bullet velocity and the users velocity you will have to aim more to the right in order for the bullet to hit the person (Depending on the distance). I know I can clone/create a brick with a velocity, but the hit detection is very glitchy due to the high velocity.

Any help/ideas would be appreciated,

Thanks :)

1 answer

Log in to vote
0
Answered by
Destrings 406 Moderation Voter
10 years ago

Tried this but it fails with small targets at high velocities, still the main idea is just to check if there are parts along a path, traversing the path in a given speed.

01function main()
02    fireAt(Workspace.PartA.Position, Workspace.PartB.Position-Workspace.PartA.Position, 500, function(parts)
03        print(parts[1].Name)
04    end)
05end
06 
07function _fireAt(origin, direction, speed, callback, size)
08    direction = direction.unit
09    size = size or 500
10    --Debug part, to see the path, you can delete this
11    local Debug = true
12    local debugPart = Instance.new("Part")
13    debugPart.Anchored = true
14    debugPart.Size = Vector3.new(1,1,1)
15    debugPart.CanCollide = false
View all 42 lines...
Ad

Answer this question