Hi, so i have this code that I modified with a lot of help from people in this community (thank you to those) and it’s basically just a simple punching system.
Currently what it does right now is, you can punch any player you’re facing if you’re facing them strictly at a 90 degree angle.
For easier gameplay I increased the magnitude to 11 studs of range because the players will have speed when they’re trying to punch eachother around.
for _, target in pairs(game.Players:GetPlayers()) do
if target.Character:FindFirstChild("Humanoid") and target.Name ~= player.Name then
local playerOfTarget = target
local Angle = 90
local EnemyPosition = target.Character.HumanoidRootPart.Position
local PlayerPosition = player.Character.HumanoidRootPart.Position
local PlayerCframe = player.Character.HumanoidRootPart.CFrame
local EnemyDirection = (EnemyPosition - PlayerPosition).Unit
local ForwardDirection = PlayerCframe.LookVector
local CosTheta = ForwardDirection:Dot(EnemyDirection)
if CosTheta > math.cos(Angle/2) then
if (target.Character.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).magnitude < 11 then
print(playerOfTarget, "was touched from distance")
end
end
end
end
An issue I noticed with this is that it’s incredibly difficult for people on tablet and mobile, even those with maybe slow mouse or lag a lot, it’s almost impossible to aim without shiftlock or unless you can catch up to them right behind them, but if the target is continously jumping or juking people will have a lot of trouble.
My goal is to try to make this easier on the players who will be using this system (especially for people on mobile)
What I had in mind was to change the 90 degrees and make it so that you can punch and knockback someone with a wider range of field of view.
I drew this picture to demonstrate (the one in the green is what i’d want, the red is currently what it is right now)
You can make that field of view wider by just increasing the angle
Theres other ways to make it less buggy like checking 2 or so studs behind the character, doing something like:
--enemy is enemy hrp cframe
--player is player hrp cframe
local dot1 = (enemy.p-(player*CFrame.new(0,0,2)).p).Unit:Dot(player.LookVector)
local dot2 = (enemy.p-player.p).Unit:Dot(player.LookVector)
if dot2 > 1 then
if math.acos(dot1) < angle/2 then
--add 2 onto 11 = 13 because youre doing it 2 studs behind
if (enemy.p-player.p).Magnitude < 13 then
--if all of these are true it should be valid
end
end
end
With this system you cant really do angles wider than 180 but at that point its kinda aimbot
If you want those ultra wide angles I could try to figure something out though
I’ve been calling this “one button gaming.” If you are on a tablet, you have to reach your target, then click again to attack. This is at a clear disadvantage to anyone who can input “two buttons” (move and attack).
If you want to level the playing field, the tablet user must be able to attack while still moving, which I suspect means what I concluded for my game: auto-punch as soon as the player is in range. You probably have to be very forgiving on angle too, as a computer user can spin the camera with the right mouse button.
Making one-button play equal the performance of two-button play is very difficult.
I remember increasing the angle but that ended up allowing people to still punch someone even when they’re fully turned around xD although this checking might be a bit better to add to the system.
Also, if I would do auto-punch, there’s no way I could just detect if someone is using on mobile or tablet? It has to work cross-platform which means i’d have to enable auto punch as something a computer user AND mobile user would use?
My game is not about PVP, so I just handed auto-attack to everyone. This is going to be a personal call, probably with lots of play testing. It is possible to distinguish what input method is being used. Touch Screen vs Mouse vs VR headset(?).
Anything between 90 and 180 should be fair game
More than 180 would make back shots be possible
If that’s not the case there could be a problem with the code