Creating a gun without Raycasting!

Normally, when I create my guns, I usually use Raycasting to create the bullet. What is a better way to create a gun with a more realistic feel to it?

2 Likes

Raycasting is probably the best way to make a gun. You might wanna use FastCast.

3 Likes

The way you raycast can make it more realistic

You can simulate spread and gravity if there are multiple raycasts being done one after another. It doesn’t have to be just a straight line from point 0 to point 1.

Raycasting with Daxter33

3 Likes

I’m not sure what you mean or if you have been misinformed, but realistic guns are created easily with Raycasting.

Simple steps:

  • Every frame, do the below
  • Cast a ray from the current bullet position to the new position (x studs forward (direction shooting) and down y studs if you want bullet drop)
  • If that ray collides, remove the bullet
  • If it does not, move the bullet to the new position and repeat the above until a hit occurs or the bullet has existed for too long

(X = velocity, y = gravity)

6 Likes

Yes, Bullet Drops, Interesting. If I may ask, how may that be done?

2 Likes

Subtract a gravity vector. For example:

local velocity = 10
local gravity = 1
local curPos = --Current position of bullet
local direction = --Direction fired (.lookVector or another unit vector)
local newPos = curPos + (velocity * direction) - Vector3.new(0, gravity, 0) --New position

Velocity is studs per frame and gravity is the gravitational force down per frame.

1 Like

The Y value also has velocity excluding gravity…

Saying that y = gravity would be assuming that the gun is ALWAYS pointed at the horizon at 0 degrees.

1 Like

No, it is gravitational force. Say you point a gun slightly down, the force will already have downward force without gravity. Gravity is a additional force, not the force pushing a object to the ground. If a rocket is upside down, gravity is only doing part of the force.

Gravity ~= Downward force

Saying y = downward force would be wrong. However, I said gravity, which is a additional force.

2 Likes

That makes sense now. When you said x studs forward, I thought you meant horizontal velocity rather than a unit vector * speed (different frame of reference that I had lol)

1 Like

I edited it for clarity, thanks for the suggestion / advice.

2 Likes