I am trying to make an hammer that push parts when it hit.
I have no clue how to do that, maybe using explosions, body-gyro or event vector-force ?!
I would like to have your idea about the question.
I juste started scripting in LuaU not so long ago so I mostly use drive-seat part to move other parts, or special joints. I even made a pickaxe recently that detect specific part to break them as the terrain, so I already have the base of my script as the detection of the part I wanna propuls. So I even know how to modify things in the part. I mean I have an access to my part and know how to change his parameters.
So this is how I detect for know.
for_, touching in pairs(workspace:GetPartBoundsInRadius(collider.Position,collider.size.X/2)) do
if touching.Name == "Box" then
print("Box touched !!!")
local box = touching
--here I Wana propulse box
break
end
end
(Also this is my first post on the dev forum so I may have forgot things that can be helpful so don’t hesitate to ask me :D)
I am not sure how to use that, may I change the relativeto to the center of mass of my box ?
And I must make a new attachment to my box to know where to put my vector?
And I can change the direction where my part is propulse by changing vector.Force ?
So I tried to use the Vector Force, I even looked up some documentation but I can’t figure how to correctly select the direction where my part must go.
Because it seems the part always go to his own X and never the X of the hammer which is bad because the part can go on you while you hit the box.
So I try to us the “collider” which is in the hammer but then the player get recoil, it’s a cool effect by the way but not what am trying to do.
So I think my problem is in the
vectorForce = Vector3.new(",",")
Because I don’t get how I can set the direction with something else than the box’s X,y and z.
Here is what I have for now
local box
local vectorForce = Instance.new("VectorForce")
local attachmentHit = Instance.new("Attachment")
attachmentHit.Parent = box
attachmentHit.Worldposition = collider.Position
vectorForce.Parent = box
vectorForce.RelativeTo = Enum.ActuatorRelativeTo.Attachement0
vectorForce.Attachement0 = attachmentHit
vectorForce.Force = Vector3.new(10000,5000,0)
So I think If I can make the attachmentHit being always up it may work whatever the angle.
-- Assuming 'collider' is the hammer
local collider = script.Parent -- Adjust this to the actual hammer part
for _, touching in pairs(workspace:GetPartBoundsInRadius(collider.Position, collider.Size.X / 2)) do
if touching.Name == "Box" then
print("Box touched!")
local box = touching
-- Create a VectorForce inside the 'Box'
local vectorForce = Instance.new("VectorForce")
vectorForce.Force = Vector3.new(0, 0, 1000) -- Adjust the force as needed
vectorForce.RelativeTo = Enum.ActuatorRelativeTo.World
vectorForce.Parent = box
vectorForce.Enabled = true
-- Optional: You can also destroy the VectorForce after a certain time
wait(1) -- Adjust the duration
vectorForce:Destroy()
break
end
end
This will have to be changed to your needs, but it would look something like this I think.