Help trying to offset a lerp

Basically what I want to do is move a part on a custom character from one place to another. The solution to this I think is to lerp it to the Humanoid Root Part position but provide another value as a Vector3 to offset it off of the humanoid root part’s position.

This is what I’ve tried so far:

playerPhysbox.CFrame = playerPhysbox.CFrame:Lerp(humanoidRootPart.CFrame + Vector3.new(5, 5, 5), 0.2)

This makes sense in my head, but it doesn’t work in Studio. Any help would be appreciated.

Is this in a local script?
How is the variable playerPhysbox set up? If it’s referencing the Player then it won’t work because the Player isn’t in the Workspace at the moment, but their Character is.

It would really help to have the entire script or the sections that deal with the part’s movement.

Have you ever thought of checking out TweenService instead? You can achieve near the same results (with customizable tweening patterns!).

1 Like

You should instead try to offset it with CFrame instead of Vector3.

Try this?

playerPhysbox.CFrame = playerPhysbox.CFrame:Lerp(humanoidRootPart.CFrame * CFrame.new(5, 5, 5), 0.2)

Also, I recommend what @Pyritium says in his reply. You should use TweenService instead of lerp for this case.

Alright, it’s part of a larger script with a lot more in but I’ll give everything that is relevant, I might have missed some stuff out so sorry if I have

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")


local playerPhysboxVector = Vector3.new(0, 1.8, 0)
local playerPhysbox = character.PlayerPhysbox
playerPhysbox.Position = humanoidRootPart.Position + playerPhysboxVector

local function onCrouch(actionName, inputState)
	
	if inputState == Enum.UserInputState.Begin then

               playerPhysbox.CFrame = playerPhysbox.CFrame:Lerp(humanoidRootPart.CFrame + Vector3.new(5, 5, 5), 0.2)

	elseif inputState == Enum.UserInputState.End then
		
                playerPhysbox.CFrame = playerPhysbox.CFrame:Lerp(humanoidRootPart.CFrame + playerPhysboxVector, 0.2)

	end
	
end

It is in a local script by the way. playerPhysbox is a part of a custom StarterCharacter. It is welded to the HumanoidRootPart using a Weld (not a WeldConstraint - this may help i’m not sure???)

@Pyritium as for using TweenService instead, my understanding is that TweenService only deals with resizing parts instead of moving their position? This part is already resized using a Tween (I’ve cut it out in the code above). I just want it’s position on the body to be different, but for it to move there smoothly and efficiently

@IVoidstarI I tried this, it seems to move the entire character as a whole (i just want this part to move on the character while the player can still move around freely - this is why I assumed Vector3 would work for me)

Thanks for your responses, hope this clarifies some stuff!

i just want this part to move on the character while the player can still move around freely

You probably shouldn’t weld the box to the character then and just directly set CFrame instead to the HumanoidRootPart and just use CFrame.lookAt to have it look towards that direction. When you weld a part to the character, since they’re both technically connected, they will both move at the same time.

Try this as an example;

playerPhysbox.CFrame = playerPhysbox.CFrame:Lerp(CFrame.lookAt(humanoidRootPart.Position, (humanoidRootPart.CFrame * CFrame.new(5, 5, 5)).Position), 0.2)

Also, TweenService is compatible with almost all properties, in this case it definitely works with CFrame and position.

Played around with both, using TweenService seems better as I can combine it with another tween resizing this part.

Thanks so much for your help! Honestly not sure how I didn’t know that TweenService did more than resizing but now I do.

1 Like