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)
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)
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