Need Help With Hiding Behind Wall Script

so he will rotate away from the wall that’s it?

1 Like

That probably would work. I would just need to make it so that they can’t interact with the wall until they are close enough to it.

1 Like

just use a proximity prompt?

nvm this

1 Like

I would need to add a proximity prompt to every single thing that you can hide behind

1 Like

whats wrong here? you can make it using a for loop

1 Like

I think I might just make it so that it only works when you get super close to the wall, and then make the player turn away from it

i’ll make a script without prompts, where do you “store” all these items? or a way to differentiate between dem

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?

you could try a script that fires when touching a wall and it plays an animation that turns you around

Rn I’m just prototyping it, so all of my items are currently in the workspace

you need a way to differentiate between these items, like a specific things with them, i’ll make a script if there is a way

I’m assuming you’re trying to make a cover system like Grand Theft Auto.

Here’s a great resource you could use to try and figure out how it’s made to then make your own system.

what’s wrong with duplicating the walls and trees and things?

Wow, that is really close to what I am trying to do

can u hide behind all the items in workspace?

Could you use MoveTo() to move the player behind the wall??

currently, yeah

don’t mind these extra words here

2 Likes

How would I make CFrame.lookAt() only affect the X and Z axis? I had this trouble with a script a while ago

When they hit h, raycast in several directions. If the raycast hits something close, use AlignPosition to move their CFrame to the correct location.

Also, it would be CFrame.lookAt(v3(p), v3(p2.X, player.Character.hrp.Position.Y, p2.Z))

here is a simple script (change it however you want)

local players = game:GetService("Players")
local userInputService = game:GetService("UserInputService")

local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("humanoid")

local itemHolder = workspace --where all the items are stored

local maxDistance = 5 --minimum distance to be able to click E

for _ , v in pairs(workspace:GetChildren()) do --you can use GetDescendants() (if you want)
	if v:IsA("BasePart") or v:IsA("MeshPart") then --checking if it's a part
		local difference = (player.Character.PrimaryPart.Position - v.Position).Magnitude --difference between player and part
		
		userInputService.InputBegan:Connect(function(input , gameProcessed)
			if difference > maxDistance then return end
			if gameProcessed then return end
			
			if input.KeyCode == Enum.KeyCode.E then
				humanoid:MoveTo(v.Position , v)
			end
		end)
	end
end