Skip to content

Commit

Permalink
checkpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
bozmir committed Dec 17, 2024
1 parent 5816ae5 commit d6f7249
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
9 changes: 5 additions & 4 deletions Assets/Scenes/Main.unity

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 28 additions & 14 deletions Assets/Scripts/KerstSpecial/RaceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ public class RaceController : MonoBehaviour
private float camFollowSpeed = 3f;
private float camYawDelta = 0;
private float rotationSpeed = 60f;
private float playerSpeed = 10f;
public float playerSpeed = 10f;
private float slipFactor = 0.99f;
public float jumpForce = 10;
private float checkPointScale = 5;

private Vector3 unityStartTarget;
private Vector3 playerMoveVector = Vector3.zero;
Expand All @@ -48,7 +49,7 @@ public class RaceController : MonoBehaviour
private int currentCoordinateIndex = 0;

private MeshCollider nothingMeshCollider;

private GameObject currentCheckpoint;

private void Start()
{
Expand Down Expand Up @@ -140,7 +141,7 @@ private void FixedUpdate()
float yDist = Mathf.Abs(floorPoint.y - player.transform.position.y);
//floorPoint.y = -1; //ugly fix but better for now
bool isGrounded = yDist < 1f;
Debug.Log("isgrounded:" + isGrounded);
//Debug.Log("isgrounded:" + isGrounded);
if(isGrounded)
{
hasJumped = false;
Expand All @@ -150,7 +151,7 @@ private void FixedUpdate()
{
playerRigidBody.transform.SetPositionAndRotation(new Vector3(playerRigidBody.position.x, floorPoint.y, playerRigidBody.position.z), player.transform.rotation);
}
Debug.Log("FLOORY" + floorPoint.y);
//Debug.Log("FLOORY" + floorPoint.y);
//playerRigidBody.transform.SetPositionAndRotation(Vector3.Lerp(player.transform.position, new Vector3(player.transform.position.x, floorPoint.y, player.transform.position.z), Time.fixedDeltaTime * 3), player.transform.rotation);
playerRigidBody.angularVelocity = Vector3.zero;
}
Expand All @@ -167,6 +168,8 @@ private void Update()
if(!isReadyForStart)
{
Coordinate nextCoord = new Coordinate(CoordinateSystem.WGS84, routeCoords[0].x, routeCoords[0].y, 0);
if(currentCheckpoint == null)
currentCheckpoint = SpawnCheckpoint(nextCoord);
//nextCoord = new Coordinate(CoordinateSystem.WGS84, 53.198472d, 5.791865d, 0);
unityStartTarget = nextCoord.ToUnity();
unityStartTarget.y = camHeight;
Expand Down Expand Up @@ -223,11 +226,17 @@ private void CheckNextCoordinate()

Coordinate nextCoord = new Coordinate(CoordinateSystem.WGS84, routeCoords[currentCoordinateIndex].x, routeCoords[currentCoordinateIndex].y, 0);
Vector3 unityCoord = nextCoord.ToUnity();
unityCoord.y = player.transform.position.y;
float distance = Vector3.Distance(player.transform.position, unityCoord);
if(distance < 2)
Debug.Log("distance to next target" + distance);
if(distance < checkPointScale)
{
Destroy(currentCheckpoint);

currentCoordinateIndex++;
nextCoord = new Coordinate(CoordinateSystem.WGS84, routeCoords[currentCoordinateIndex].x, routeCoords[currentCoordinateIndex].y, 0);
Debug.Log("WE HIT THE COORD" + currentCoordinateIndex);
currentCheckpoint = SpawnCheckpoint(nextCoord);
}
}

Expand Down Expand Up @@ -338,15 +347,7 @@ private void GetCoordinatesForRoute()

//foreach(Vector2 c in routeCoords)
//{
// Coordinate coord = new Coordinate(CoordinateSystem.WGS84, c.x, c.y, 0);
// GameObject routeObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
// routeObject.transform.localScale = Vector3.one * 5f;
// WorldTransform wt = routeObject.AddComponent<WorldTransform>();
// GameObjectWorldTransformShifter shifter = routeObject.AddComponent<GameObjectWorldTransformShifter>();
// wt.SetShifter(shifter);
// Vector3 unityCoord = coord.ToUnity();
// unityCoord.y = 2;
// routeObject.transform.position = unityCoord;
//
//}
}
else
Expand All @@ -355,6 +356,19 @@ private void GetCoordinatesForRoute()
}
}

private GameObject SpawnCheckpoint(Coordinate coord)
{
GameObject routeObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
routeObject.transform.localScale = Vector3.one * checkPointScale;
WorldTransform wt = routeObject.AddComponent<WorldTransform>();
GameObjectWorldTransformShifter shifter = routeObject.AddComponent<GameObjectWorldTransformShifter>();
wt.SetShifter(shifter);
Vector3 unityCoord = coord.ToUnity();
unityCoord.y = 3;
routeObject.transform.position = unityCoord;
return routeObject;
}

List<Vector2> ExtractLatLon(string gpxContent)
{
List<Vector2> latLonList = new List<Vector2>();
Expand Down

0 comments on commit d6f7249

Please sign in to comment.