Ray isn't actually shoot at where mouse is aimed

FastCast is only modules
image

image

Oh, is that with the tester gun they provide??

Having looked at their code, problem is using mouse doesn’t take into account collision groups. When shooting at say a forcefield, the mouse.Hit returns that forcefield, but the bullet needs to pass that, and so the bullet gets shot at a weird angle. So I can’t use Mouse.Hit for that reason

well what is the Direction are you sending

local Mouse = Player:GetMouse()
	
local directionalCF = CFrame.new(Vector3.new(), (Mouse.Hit.Position - firePoint).Unit)
	
local Direction = (directionalCF * CFrame.fromOrientation(-0.05, 0, 0) * CFrame.fromOrientation(0, 0, 0)).LookVector

But if you look when I shoot through a forcefield, the bullet goes askew, This was one of the reasons I resorted to camera, as I could ignore forcefields.

Can see when shooting at parts, it’s great, but when shooting through the field, your bullet goes off skew

EDIT Hold on gif glitched, lemme get another vid

As you can see, when shooting (not through forcefield part) the bulelts line up with my scope (they not perfectly centre due to gravity) but when Ishoot through the forcefield, they are wayyy off

hmmm
This looks more confused than I imagined :slight_smile:

So I’ve had this exact problem before. And none of it requires all this stuff.
All I did to fix it was:

local rayDirection = ((MouseHit - BulletStartPart.Position).Unit) * 100 --this is the number of how far the raycast goes

And it works perfectly fine. I’m pretty sure this will work. (At least for you)

I used Mouse.Hit.p, and a part for the start of the bullet.

As the above problem, it works great on normal parts, but when shooting through forcefields, it goes way off. This is due to Mouse.Hit not taking into account collision groups, and thus it returns the position on the forcefield, when it should return the position beyond that. Thus, I can’t use Mouse.Hit.Position AT ALL

You can add a filter so the player mouse can not detect this forcefields parts

How? As far as I was aware, you could have 1 instance be filtered, however I need several objects to be ignored from the raycast

CastParams.FilterDescendantsInstances = {
	Camera,
	Character,
	Splatter,
	Bullets,
	CurrentMap.TeamDoors[player.Team.Name]
}

CastParams.CollisionGroup = player.Team.Name == "Blue" and "BluePaint" or "RedPaint"

TargetFilter

Target filter can only filter 1 item (as I said above) thus can’t be used

this is not true
Well, wait, I’ll find a way

It is true
image

hmmm okay
then but all the forcefields parts inside one model

… you’re not listening. It’s not just forcefields I need to ignore. It needs to ignore EVERYTHING here

CastParams.FilterDescendantsInstances = {
	Camera,
	Character,
	Splatter,
	Bullets,
	CurrentMap.TeamDoors[player.Team.Name]
}

CastParams.CollisionGroup = player.Team.Name == "Blue" and "BluePaint" or "RedPaint"

I can’t just put all these items into one model

But this is not the mouse filter.
CollisionGroup is something else

Well, my last attempt, are you already filtering the mouse In another scripts or not?

i don’t think the issue is the raycast. you seem to be shooting the bullet from the barrel, but raycasting from the camera. Meaning that the bullet will follow the raycast of the camera, but be positioned to the barrel of the gun.

What i’d reccomend you to do is to ffirst raycast from the camera, take the position it hit, and then to take the normalised vector from the position where it hit, to the position where the barrel is (HitPos-BarrelPos).normalised.
Then, you can use that normalised vector as the direction the bullet should travel.

2 Likes

This seemed to work well in most cases! Small problem is the ray returns at times? The ray should NEVER return nil, and even if you aim into space, it should still shoot

local HitRaycast = workspace:Raycast(
	UnitRay.Origin,
	UnitRay.Direction * 10000,
	CastParams
)
local Direction = (HitRaycast.Position - FirePoint).Unit

attempt to index nil with ‘Position’

when it doesn’t hit anything, it will return nill, because the object it has hit is nill. there is none.

you should always check if a raycast is nill.

1 Like