How would I make the player push an object?

I have a clock and I want the player to be able to push the hands on the clock by pressing ‘E’ and walking in a direction.

If the player was standing at the star and the player presses ‘E’, then I want them to be able to walk forward or backwards, pulling or pushing the hand around. I have the “Pressing ‘E’” thing down, I just don’t know how I would position the player and make the hand move with them in such a manor, any suggestions?

2 Likes

Your rotation would probably have to looks something like this:

local arm = <your clock arm>

local pushing = true -- Set this to true when player begins pushing
repeat
	arm.CFrame *= CFrame.Angles * direction-- Make the correct angles
	task.wait()
until not pushing

Direction should be 1, 0 or -1. 1 would be holding W, -1 would be holding S and 0 would be nothing.

2 Likes

Is there any way that I could detect when and if the player starts to go left or right so I could stop turning the arm? Also, how would I keep the hand locked on the center so the player can’t just walk away with it?

2 Likes

You could create a clone of the char and teleport the actual char away. You can script your camera for a more cinematic look.

You could ignore left & right movement, and make the player walk away from it by pressing E again

2 Likes

Well, I plan on animating it, so the player grabs onto it, so it actually looks like they’re pushing it.

I started getting it to work, except that after a certain point, after the player keeps walking, it starts going the other way (Sorry for the bad quality, I used Roblox’s built in recording system):

robloxapp-20220623-1603065.wmv (2.4 MB)

The reason it is doing this is because I am doing using .MoveDirection.X to check for the direction:

if (_localHumanoid.MoveDirection.X < 0) then
	direction = 1
elseif (_localHumanoid.MoveDirection.X > 0) then
	direction = -1
end				

The only problem is that, because it’s a circle, after I walk for so long it reverses. Is there a better way of getting the player’s direction?
(Also, I can’t just use ‘W’ and ‘S’ because I want this to be available on mobile)

1 Like

You could compare the move direction with the humanoidRootParts look direction (or -ZVector). If they are somewhat aligned then they are moving forward

1 Like

Thank you, I got it working, but I actually used :Dot() to get the players direction.

2 Likes