Need help with thor's hammer's mechanics

I am working on thor’s hammer wherein the idea is simple, you throw the hammer by left clicking and summon it back by right clicking. I have completed the throw part however I have a problem making the summoning of the hammer work harmoniously.
Excerpt:

if State == "Throw" then
local BodyVelocity = Instance.new("BodyVelocity",Mjolnir)
		BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		BodyVelocity.velocity = Direction.LookVector * Speed
	
	elseif State == "Retrieve" then
		-- Retrieve funcion
		Mjolnir.Parent = Character
		local BodyVelocity = Mjolnir.BodyVelocity
		BodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		BodyVelocity.Velocity = RightHand.CFrame.LookVector * 100

The Result:
https://streamable.com/e2wz2f

The throw works but the return doesn’t. My idea is to have the hammer travel infinitely(Assuming that is possible and it doesn’t get destroyed after travelling a certain distance) once thrown and when the player clicks the right mousebutton, it’ll return by travelling back. I used bodyvelocity for the throw part and bodyposiition for the summon but that didn’t work, I figured it was because of the existing bodyvelocity in the part. I then switched both to body velocity and using the same bodyvelocity, thinking that the problem was because a new bodyvelocity would be unable to override the existing one but that didn’t work either.
How can I make it so that the same hammer would come travelling back to the character, would I have to use raycasting?

This line is not correct BodyVelocity.Velocity = RightHand.CFrame.LookVector * 100.
You’re basically saying the BodyVelocity to go towards where the right hand is looking at.
If I recall correctly, this is the way to make a part go towards another part with a BodyVelocity:

BodyVelocity.Velocity = (Mjolnir.Position - RightHand.Position).Unit * -100

If it still goes away from the hand, try making the 100 positive instead of negative.

Alright I tried it and the hammer just continues travelling in the same direction, not turning back. I presumed I’d have to ovveride it’s existing bodyvelocity to get it to come back to my character, don’t I?

I’d say to delete the old body velocity and replace it with the new one.

I don’t think so, you can change the velocity of an already existing BodyVelocity. The only thing I’d say is to check if there already is an existing BodyVelocity inside the hammer when the state is “Throw”, and if there is then destroy it.

if State == "Throw" then
   if Mjolnir:FindFirstChildWhichIsA("BodyVelocity") then
      Mjolnir:FindFirstChildWhichIsA("BodyVelocity"):Destroy()
   end

   local BodyVelocity = Instance.new("BodyVelocity",Mjolnir)
   BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
   BodyVelocity.velocity = Direction.LookVector * Speed

--etc...
1 Like