Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class GorillaTagAntiCheat : MonoBehaviour
- {
- public float maxSpeed = 12f; // Maximum speed the player is allowed to move
- public float maxTeleportDistance = 10f; // Maximum distance the player can move in a single frame without being flagged
- private Vector3 lastPosition;
- private float lastCheckTime;
- void Start()
- {
- lastPosition = transform.position;
- lastCheckTime = Time.time;
- }
- void Update()
- {
- CheckPlayerSpeed();
- CheckForTeleportation();
- }
- void CheckPlayerSpeed()
- {
- float distanceTraveled = Vector3.Distance(lastPosition, transform.position);
- float timeElapsed = Time.time - lastCheckTime;
- float currentSpeed = distanceTraveled / timeElapsed;
- if (currentSpeed > maxSpeed)
- {
- Debug.LogWarning("Speed hack detected!");
- HandleCheating();
- }
- lastPosition = transform.position;
- lastCheckTime = Time.time;
- }
- void CheckForTeleportation()
- {
- float distanceMoved = Vector3.Distance(lastPosition, transform.position);
- if (distanceMoved > maxTeleportDistance)
- {
- Debug.LogWarning("Teleportation detected!");
- HandleCheating();
- }
- lastPosition = transform.position;
- }
- void HandleCheating()
- {
- // Handle cheating by logging, kicking, or taking other actions
- Debug.Log("Cheating action handled.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement