Prevent Projectile Phasing Through Object

I am making a projectile that will anchor itself when it hits a wall or the ground.
I am clueless to how to achieve this,I used if hit.Classname == “Part” but it didnt work.

My code:
local sword2 = script.NoblePhantasms.Sword1:Clone()
sword2.CFrame = sword1.CFrame
sword2.Anchored = false
sword2.Transparency = 0
sword2.Material = “Metal”
sword2.Parent = game.Workspace
sword2.ParticleEmitter2.Enabled = false
sword2.Color = Color3.new(0.45098, 0.45098, 0.45098)
sword2.Trail.Enabled = true

		local bv = Instance.new("BodyVelocity",sword2)
		bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		bv.Velocity = ((extra1 - sword2.Position).unit) * 100
		sword2.CFrame = CFrame.lookAt(sword2.Position,extra1)
		sword2.Orientation = sword2.Orientation + Vector3.new(-90,-360,360)
		bv.Name = "Force"
		sword1:Destroy()
		game.Debris:AddItem(sword2,10)
		
		
		
		local debounce = false
		sword2.Touched:Connect(function(hit)
			if hit.Parent.Humanoid and debounce == false then
				if hit.Parent.Name == player.Name then return end
				if hit.Parent ==  game.Workspace then sword2.Anchored = true
					
				end
				if hit.Parent:FindFirstChild("Iframes") then
					return
				end
				sword2:Destroy()
				local StunHandler = require(game.ReplicatedStorage.StunHandlerV2)

				StunHandler.Stun(hit.Parent.Humanoid, 0.3, hit.Parent.CanAttack)
				local stun = game.ReplicatedStorage.ExtraFolder.StunnedBillBoard:Clone()
				stun.Parent = hit.Parent.Head
				game.Debris:AddItem(stun,0.3)
				hit.Parent.Humanoid:TakeDamage(8)
				local hiteffect = script.SlashParticleKeeper.HitEffect2:Clone()
				hiteffect.Parent = hit.Parent.HumanoidRootPart
				hiteffect.HitEffect:Emit(1)
				hiteffect.Lines:Emit(1)
				game.Debris:AddItem(hiteffect,1)

				debounce = true
			end
		end)

The projectiles I want is something like this (King of Heroes) The Roblox Gilgamesh Experience - YouTube

I see two options here,

Use FastCast or shoot a Raycast for every frame that the projectile is alive.

1 Like

Hmm can you perhaps send me videos or website on fastcast?
I am new to raycast. Thank you.

I think FastCast might be the simpler(And best) option. Here you go

1 Like

Alright I manage to make it work thank you but I ran into four problems and I hope you can help.

1)The projectile instantly teleports to the position the mouse is pointing.
I want the projectile to go at least slower to be seen by players.(the projectile when traveling to the end point can be seen)

2)I never used fastcast so I am not sure how do I change the projectile orientation.Right now the projectile is upsidedown.

3)I am not sure how to anchor the sword when the fastcast ends when getting in contact with a wall or object.

4)I am not using a tool and when I shoot the arrow with the bow the arrow will stop due to it touching the bow.
(line 1081 CastParams.FilterDescendantsInstance = {player.Character,ProjectileFolder})

unknown-3
unknown-4

here is a gun that uses fastcast. I recommend you disect the gun’s code to see how to use fastcast and apply it to your system

1 Like
  1. Lower the bullet speed

  2. Times the offset by some cframe like this * CFrame.Angles(value1, value2, value3)
    image

  3. The onRayHit returns the projectile you shot. So you can do something like this bullet.Anchored
    image

And I don’t understand what you mean in the fourth question

1 Like

In the fourth I meant like the projectile is launched and it works fine.When it touched player character it will ignore it and continue to go further.
But how do I ignore another object other than just player character.

The projectile will go through every object that is inside this table (or if the object is a descendant of something inside the table)
image

1 Like