How to make a part face the direction a player is facing, and add velocity?

how to make a part face the direction a player is facing, and add velocity?

Id say get the player’s HumanoidRootPart, or any other part of their body and get the CFrame of it, then set the CFrame of the part to the player’s character part and add another line stating velocity

part.Velocity = 10

Part.CFrame = CFrame.lookAt(Part.Position, Character:GetPivot().Position)
Solves the first part of your question.
Part.Velocity = Vector3.new(0, 0, -10) --Change '-10'.
Solves the second part of your question.

1 Like

The first part worked, but for the second part, how do I make the object move straight (the direction its facing)?

Do

Part.Velocity = HumanoidRootPart.CFrame.LookVector * 100

The 100 make the part move faster

my part doesnt have a HumanoidRootPart. Its just a part with a script inside.

Please try and apply what he’s giving you, to get the direction of a part as a unit vector call .LookVector on the CFrame of the part, by applying that to the velocity of a part it’ll move in that direction, multiplying by the amplitude (in that case 100) increases the velocity in that direction.

I mean the player character HumanoidRootPart

Part.Velocity = Part.CFrame.LookVector * n --Replace 'n'.

1 Like

i tried to do that but it didnt work. here is what happens

This is my current script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local shootEvent = Instance.new("RemoteEvent", ReplicatedStorage)
shootEvent.Name = "shootEvent"
local Part = game.Workspace.Ball




local function onShootEventFired(player, power)
	print(power)
	local Character = player.Character or player.CharacterAdded:Wait()
	local is_touching = false
	local touched_parts = game.Workspace.Ball:GetTouchingParts()

	for _, v in touched_parts do
		if v.Parent == player.Character then
			is_touching = true
			break
		end
	end
	print(is_touching)
	if is_touching then
		if power < 50 then
			Part.CFrame = CFrame.lookAt(Part.Position, Character:GetPivot().Position)
			Part.Velocity = Part.CFrame.LookVector * power
		else
			Part.CFrame = CFrame.lookAt(Part.Position, Character:GetPivot().Position)
			Part.Velocity = Part.CFrame.LookVector * 50
		end
		
	end
end

shootEvent.OnServerEvent:Connect(onShootEventFired)

I tried making the values negative but it didn’t change anything.

If you want it to go in the other direction you can use the character’s ‘LookVector’ instead.
Part.CFrame = Character:GetPivot().LookVector * n

1 Like