Player not flinging to where player is looking at

so, im making a game called “Hammer” and im stuck in this dumb issue.

i want the dummy to fling to where the player head is looking at but
the dummy would not fling to the right direction
image

the code where the issue is expected

local function touched(h)
	h = h.Parent
	if isattacking and deb then
		deb = false
		if h:FindFirstChild("Humanoid") and not h:FindFirstChild("ForceField") then
			h.Humanoid:TakeDamage(25)
			h.Humanoid.Sit = true
			--fling the player(not really)
			local bodyvelocity = Instance.new("BodyVelocity")
			bodyvelocity.Parent = h.HumanoidRootPart
			bodyvelocity.Velocity = CFrame.lookAt(script.Parent.Parent.Head.Position,h.Head.Position).Position -- the part
			bodyvelocity.P = 1250
			bodyvelocity.MaxForce = Vector3.new(8000,8000,8000)
			game:GetService("Debris"):AddItem(bodyvelocity,0.2)
		end
	end
end

did i do something wrong? if so how can i fix it.

thanks

your code doesnt specify where the dummy will go on the fling

really?

You have .Position).Position in your code here:

h.Head.Position).Position -- the p

the velocity is a vector3 value, and position is a vector3.

oh i get it, im not specifying the orientation, how would i go about that?

theres an orientation property of humanoid root part that you can change

x = CFrame.lookAt(script.Parent.Parent.Head.Position,h.Head.Position).Position.X
y = CFrame.lookAt(script.Parent.Parent.Head.Position,h.Head.Position).Position.Y
z = CFrame.lookAt(script.Parent.Parent.Head.Position,h.Head.Position).Position.Z

im not quite sure i havent really done anything like this before but perhaps something like that?

i think that does the same thing? because your only specifying position

this might sound a bit weird but

what if you made it so when you click the hammer, it walks the player forward slightly but enough to show the change of humanoidrootparts position? and then you keep moving the dummy forward in the same direction that the player first stepped

the player would go forward on a path to the dummy’s humanoid rootpart
anywho i dont really know how to explain it, its as complicated as it sounds

I wanna do it with bodyvelocities instead

You can just change the .position to .lookvector so it can convert it to a vector unit that will make it launch the player to that direction.

Ig I’ll try it when I get back in pc and that’s tommorow

You should never have a .Position when using body velocity since it is just linear velocity, hence; CFrame.lookAt(script.Parent.Parent.Head.Position,h.Head.Position).LookVector * speed You will just need a unit vector for body velocity and other movers but for body position it requires a position.

1 Like

thanks, it worked

You can also use something like this without creating a cframe; (h.head.Position-script.Parent.Parent.Head.Position).Unit —the direction goes first then the origin when using .Unit but in .Magnitude it is the reverse.

1 Like