I am trying to make a script where when the player hits “H” on their keyboard, it makes them hide behind a wall.
I managed to get a raycast to detect if the player is close to a wall when they hit “H,” but I can’t get the player to automatically move a certain distance closer to the wall.
I tried to separate the space in between the player and the wall into four separate positions (example shown below) to mess around with how far the player should be from the wall, but it didn’t work.
(Imagine each of the vertical lines as a position, and the horizontal line as the distance between the player and the wall)
By now, I don’t really want the “four different positions” part, I just need the player to be a set distance from the wall
Here is the part of the code I need help with:
if result then
local hit = result.Instance
if hit.ClassName == "Part" or hit.ClassName == "Union" then
local pos1 = result.Position
local pos2 = character.HumanoidRootPart.Position
local humanoid = character:FindFirstChild("Humanoid")
Yeah, it’s a bit hard to explain, but when the player approaches the wall and hits “H” on their keyboard, I want them to automatically go closer to the wall and turn their back towards it.
You can either make an animation or move the player close to the wall with for ex. a Tween where it moves close behind the wall and if needed rotates to your desired direction?