You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/Source/Scripts/SurfaceGenerator.cs

33 lines
888 B
C#

3 months ago
using System.Collections.Generic;
using Unity.AI.Navigation;
using UnityEngine;
using static D2D.Utilities.CommonGameplayFacade;
public class SurfaceGenerator : MonoBehaviour
{
[SerializeField] public GameObject surfacePrefab;
2 months ago
[SerializeField] private Vector3 Grid = new Vector3(10, 0, 10);
3 months ago
[SerializeField] private int checkFrames = 4;
// ~~~~ Round to nearest Grid point ~~~~
public Vector3 SnapCalculate(Vector3 playerPos)
{
float x = playerPos.x - playerPos.x % Grid.x;
float z = playerPos.z - playerPos.z % Grid.z;
return new Vector3(x, 0, z);
}
private void Update()
{
if (Time.frameCount % checkFrames == 0)
{
CheckGround();
}
}
private void CheckGround()
{
var newPos = SnapCalculate(_formation.transform.position);
transform.position = newPos;
}
}