Gun With Limited Reach

So hey I was wondering whether it was actually possible to make a gun which has a reach of 3 studs and could deal some knockback.

1 Like

Not sure what you mean by this

And yes Dealing knockback is quite easy Use body movers I personally just add on to the velocity(deprecated Property of basepart)

1 Like

I mean that the gun can only shoot 3 studs away…

1 Like

Do you mean the gun is 3 studs in length, or do you really mean the projectile can only reach 3 studs, because that seems dumb, or what

1 Like

projectile can only reach 3 studs

1 Like

A ray or a moving projectile? you can* just experiment with BodyMover 's if you want a moving projectile

Roblox has a built-in feature called Magnitude, you can use it to get the distance between two objects.

https://developer.roblox.com/en-us/articles/Magnitude

  • You can first get the positions of your character and the object.

  • Then use magnitude to compare the distance between you and the object.

  • Lastly, do something like:

local magnitude = (Character.HumanoidRootPart.Position - ObjectHit.Position).magnitude

if magnitude < 4 then --// if the object is less than 3 studs away
    -- Do stuff
else
    -- Ignore object
end
1 Like