I have a “Cutscene” that plays whenever an NPC tries to attack a player which is at very low health.
In the cutscene, the player gets teleported 5 studs back, however the problem is if the player is next to a wall when the cutscene plays, they will phase through it.
You didn’t really explain what you wanted.
local someParameters = RaycastParams.new()
someParameters.FilterType = Enum.RaycastFilterType.Whitelist
someParameters.FilterDescendantsInstances = {} -- ideally, try to put all the parts the character needs to account for when doing the cutscene. Maybe the entire map.
local function checkBehindTheCharacter()
local humanoidRootPart -- where are you
local direction = humanoidRootPart.CFrame.LookVector * -5
local raycastResult= workspace:Raycast(humanoidRootPart.Position, direction, someParameters)
if raycastResult then
return false
else
return true
end
end
local isItOkayToTeleportFiveStudsBack = checkBehindTheCharacter()
This will return a bool that if true, there is no wall within 5 studs behind the character. If it’s false maybe you shouldnt teleport the character. If you absolutely need to, maybe you can take the cutscene elsewhere thats guaranteed an open area.
wanted a solution to solve what i stated
i have also thought about using a ray to detect if the cutscene should be played or not, but think about this in a gameplay perspective: if the player is too close to the wall, they wont get another chance to live (as in the cutscene gives a chance to live) and instead the monster would just kill you
if you want more info about the cutscene: Once a monster is about to attack a player that is at less than 10hp, a cutscene will play and the player will be able to dodge the “final attack”, but in order for the animations to fit the cutscene (since the monster lunges forward in the cutscene) the player will needed to be teleported back for the animations to look good.
U could turn the Player with Orientation to the other Side where no walls are
so i edited the function and added more to it, however even when there is a wall, it will still return true, so the character gets teleported through the wall
local canTPBack = false
local canTPForward = false
local canTPLeft = false
local canTPRight = false
local function checkAroundTheCharacter(target)
local humanoidRootPart = target:FindFirstChild("HumanoidRootPart")-- where are you
local back = humanoidRootPart.CFrame.LookVector * -5
local forward = humanoidRootPart.CFrame.LookVector * 5
local left = humanoidRootPart.CFrame.RightVector * 5
local right = humanoidRootPart.CFrame.RightVector * -5
local backResult= workspace:Raycast(humanoidRootPart.Position, back, someParameters)
local ForwardResult= workspace:Raycast(humanoidRootPart.Position, forward, someParameters)
local LeftResult= workspace:Raycast(humanoidRootPart.Position, left, someParameters)
local RightResult= workspace:Raycast(humanoidRootPart.Position, right, someParameters)
local foundPos = false
if not foundPos then
if backResult then
canTPBack = false
foundPos = false
else
canTPBack = true
foundPos = true
end
if ForwardResult then
canTPForward = false
foundPos = false
else
canTPForward = true
foundPos = true
end
if LeftResult then
canTPLeft = false
foundPos = false
else
canTPLeft = true
foundPos = true
end
if RightResult then
canTPRight = false
foundPos = false
else
canTPRight = true
foundPos = true
end
end
end
here is also the code im using to teleport the players (yes ik this is all pretty messy)
checkAroundTheCharacter(target)
if canTPBack then
print('tp back')
targethrp.CFrame = CFrame.new(hrp.Position) * CFrame.new(0, 0, 6)
elseif canTPForward then
print('tp forward')
targethrp.CFrame = CFrame.new(hrp.Position) * CFrame.new(0, 0, -6)
--hrp.CFrame = CFrame.new(targethrp.Position) * CFrame.new(0, 0, 6)
elseif canTPLeft then
print('tp left')
targethrp.CFrame = CFrame.new(hrp.Position) * CFrame.new(-6, 0, 0)
elseif canTPRight then
print('tp right')
targethrp.CFrame = CFrame.new(hrp.Position) * CFrame.new(6, 0, 0)
end
Although it may never occur, what if there are walls surrounding the character? Your system needs a way to create an open area for the cutscene to take place. Having the NPCs only be in open areas might not be the desired behavior, so I suggest creating open areas around the map for cutscenes to take place then you can teleport the NPC and character to the nearest area.
A lot of the games I play, such as far cry and ghost recon have special attacks, like using a knife on an enemy. Those always play a special sort of ‘cut scene’ type animation, however, I have noticed that when in a tight space, where things would clip through walls or other objects, the cut scene doesn’t play.
So I would suggest, simply, checking of a wall or other is in the way, and if it is, just don’t play the cutscene.
the cutscene is a gameplay cutscene, which means it takes place in action wherever the player is on the map, and there are always walls surrounding the player as the map is set in a house. there are open areas however the player could be in some hallways which causes the glitch.
so then what happens? when they dont play the special attack do they just normal attack you? the reason i dont do that is because that could be annoying gameplay-wise, imagine your at 1hp and instead of the game giving you another change for the special attack, they just normal attack and kill you. if the playing is in a spot where the cutscene literally couldnt play then yeah it wouldnt be played
It will still do the special attack, just the animation doesn’t happen, depending on the attack, it will either show a normal attack or only show the attack on me (doing the attacking) but not show it on the victim (just shows normal attack animations)
Of course this really depends on how you are using the attack. If clipping through the walls is going to happen a LOT, such as its a fairly common special attack, and there are many closed narrow spaces in your game, then this probably isn’t the best solution.
so i guess i could do a different finish attack animation then the one im currently using