Direction Problem/Bug

Hello every developpers !
I want to create a wand game when you shoot someone, he is propulsed in the direction of the shot.
But it don’t work correctly, it go to the same direction (and the wrong direction)

The situation :

The Code :

function onTouched(hit)
	local character = hit.Parent
	if character and character:findFirstChild("Humanoid") then
		character.Humanoid.PlatformStand = true
		local b = Instance.new("BodyPosition")
		b.position = Vector3.new(100, 20, 100)
		b.maxForce = Vector3.new(5000, 5000, 5000)
		b.Parent = character.Torso
		wait(0.05)
		b.Parent = nil
		wait(1)
		character.Humanoid.PlatformStand = false
	end
end
script.Parent.Touched:connect(onTouched)

Please help me : (

Replace:

with:

local strength = 100
b.position += (b.Position - script.Parent.Position).Unit * strength

The power has weakened after replace

The issue with your code is that you are always setting the position of the BodyPosition to Vector3.new(100, 20, 100), which is causing all the characters to move in the same direction. Instead, you need to calculate the direction from the point where the player was hit to the point where the wand was fired and use that direction to set the position of the BodyPosition.

Try this:

function onTouched(hit)
    local character = hit.Parent
    if character and character:FindFirstChild("Humanoid") then
        character.Humanoid.PlatformStand = true
        local b = Instance.new("BodyPosition")
        b.maxForce = Vector3.new(math.huge, math.huge, math.huge)
        b.position = (hit.Position - script.Parent.Position).Unit * 500
        b.Parent = character.Torso
        wait(0.05)
        b.Parent = nil
        wait(1)
        character.Humanoid.PlatformStand = false
    end
end

script.Parent.Touched:Connect(onTouched)

I test but the Dummy has disapear when i shoot him

It’s possible that the dummy is disappearing because it is being destroyed when it collides with something. This can happen if the dummy has a Part object as its parent and the CanCollide property of the Part is set to true.

To prevent the dummy from being destroyed, you can set the CanCollide property of the dummy’s parent object to false before shooting the dummy, and then set it back to true after a short delay x

It’s like this : (30 lettersssss)

I disable collide of everyparts of the dummy but it don’t work : (

It’s not because of the math.huge ?

Do you have any way to access the character of the original player casting the projectile?

Replace:

with:

local strength = 100
b.position += ((b.Position - script.Parent.Position).Unit + (Vector3.yAxis*20)) * strength

don’t work too, sorry : ( I don’t know what don’t work.

Increase the wait(0.05) to wait(0.2).