How can I add vertical direction to my current backstab code?
Asked by
6 years ago Edited 6 years ago
Hi everyone!
I am currently attempting to improve my back-stab code by adding y-direction dependency. Right now, I am purely shooting a ray straight out of the LocalPlayer's HumanoidRootPart. I am curious as to how I could make it so the ray's direction also caters to the y-direction which the player is looking (the game forces first person, so I assume this would involve the camera to some degree).
I'm not exactly sure where to start in order to make this amendment, but all help and tips are appreciated!
Here is my current code:
02 | local Ray = Ray.new(C.Character.HumanoidRootPart.Position, C.Character.HumanoidRootPart.CFrame.lookVector * 4 ) |
03 | local Part, Pos, Normal = workspace:FindPartOnRayWithIgnoreList(Ray, { C, workspace.CurrentCamera, C.Character [ "Right Arm" ] , C.Character [ "Left Arm" ] } ) |
06 | if Part.Name = = ( "Torso" or "Left Arm" or "Right Arm" or "Head" or "Right Leg" or "Left Leg" ) then |
08 | local Product = game.Workspace [ V.Name ] .Torso.CFrame.lookVector:Dot(C.Character.HumanoidRootPart.CFrame.lookVector) |
10 | ChangeMouseIcon( "EnemyHit" ) |
This code will check to make sure that you are behind the player you are stabbing, and that you can reach them. I'm not sure how to manipulate the ray's CFrame in order to respect the CurrentCamera's y-direction.
A visual interpretation of the change I am attempting to make:
Current: https://imgur.com/a/VwpYz0l
Goal: https://imgur.com/a/2joQ9ro