car obstacle done
This commit is contained in:
parent
1b09d74473
commit
944ccf8a01
2 changed files with 235 additions and 1 deletions
|
@ -12,6 +12,11 @@ public class Car : MonoBehaviour
|
|||
public Transform playerRig; // Assign your XR Rig here
|
||||
public Transform startPoint; // Assign the starting point here
|
||||
|
||||
public Transform[] waypoints; // List of waypoints
|
||||
public float speed = 3.0f; // Speed of movement
|
||||
public float rotationSpeed = 5.0f; // Smooth turning speed
|
||||
|
||||
private int currentWaypointIndex = 0; // Starting at the first waypoint
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
Debug.Log("Triggered by: " + other.name);
|
||||
|
@ -29,4 +34,38 @@ public class Car : MonoBehaviour
|
|||
playerRig.position = startPoint.position + offset;
|
||||
playerRig.rotation = startPoint.rotation;
|
||||
}
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (waypoints.Length == 0) return;
|
||||
|
||||
MoveTowardsWaypoint();
|
||||
RotateTowardsWaypoint();
|
||||
}
|
||||
|
||||
void MoveTowardsWaypoint()
|
||||
{
|
||||
Transform target = waypoints[currentWaypointIndex];
|
||||
transform.position = Vector3.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
|
||||
|
||||
// Check if the object has reached the waypoint
|
||||
if (Vector3.Distance(transform.position, target.position) < 0.1f)
|
||||
{
|
||||
// Move to the next waypoint in a loop
|
||||
currentWaypointIndex = (currentWaypointIndex + 1) % waypoints.Length;
|
||||
}
|
||||
}
|
||||
|
||||
void RotateTowardsWaypoint()
|
||||
{
|
||||
Transform target = waypoints[currentWaypointIndex];
|
||||
Vector3 direction = (target.position - transform.position).normalized;
|
||||
|
||||
if (direction != Vector3.zero)
|
||||
{
|
||||
Quaternion lookRotation = Quaternion.LookRotation(direction);
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, rotationSpeed * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77417,6 +77417,37 @@ Mesh:
|
|||
offset: 0
|
||||
size: 0
|
||||
path:
|
||||
--- !u!1 &403317235
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 403317236}
|
||||
m_Layer: 0
|
||||
m_Name: Waypoint 3
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &403317236
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 403317235}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: -47.57, y: -0.679, z: 48.86}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 2111293181}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!43 &403770795
|
||||
Mesh:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -102311,6 +102342,37 @@ Mesh:
|
|||
offset: 0
|
||||
size: 0
|
||||
path:
|
||||
--- !u!1 &457169487
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 457169488}
|
||||
m_Layer: 0
|
||||
m_Name: Waypoint 4
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &457169488
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 457169487}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: -47.82, y: -0.679, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 2111293181}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!43 &458987413
|
||||
Mesh:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -210577,6 +210639,37 @@ Mesh:
|
|||
offset: 0
|
||||
size: 0
|
||||
path:
|
||||
--- !u!1 &983262429
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 983262430}
|
||||
m_Layer: 0
|
||||
m_Name: Waypoint 2
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &983262430
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 983262429}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: -0.679, z: 48.53}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 2111293181}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!43 &984006655
|
||||
Mesh:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -260959,6 +261052,7 @@ GameObject:
|
|||
- component: {fileID: 1273264845}
|
||||
- component: {fileID: 1273264844}
|
||||
- component: {fileID: 1273264843}
|
||||
- component: {fileID: 1273264848}
|
||||
m_Layer: 0
|
||||
m_Name: Car vroom
|
||||
m_TagString: Untagged
|
||||
|
@ -260980,6 +261074,13 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
playerRig: {fileID: 1988509986}
|
||||
startPoint: {fileID: 1305339138}
|
||||
waypoints:
|
||||
- {fileID: 2033759573}
|
||||
- {fileID: 983262430}
|
||||
- {fileID: 403317236}
|
||||
- {fileID: 457169488}
|
||||
speed: 4.5
|
||||
rotationSpeed: 5
|
||||
--- !u!65 &1273264844
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -261060,12 +261161,39 @@ Transform:
|
|||
m_GameObject: {fileID: 1273264842}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 33.64, y: 20.81, z: 1076.25}
|
||||
m_LocalPosition: {x: 44.08, y: 20.81, z: 1076.25}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!54 &1273264848
|
||||
Rigidbody:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1273264842}
|
||||
serializedVersion: 4
|
||||
m_Mass: 1
|
||||
m_Drag: 0
|
||||
m_AngularDrag: 0.05
|
||||
m_CenterOfMass: {x: 0, y: 0, z: 0}
|
||||
m_InertiaTensor: {x: 1, y: 1, z: 1}
|
||||
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ImplicitCom: 1
|
||||
m_ImplicitTensor: 1
|
||||
m_UseGravity: 1
|
||||
m_IsKinematic: 1
|
||||
m_Interpolate: 0
|
||||
m_Constraints: 0
|
||||
m_CollisionDetection: 0
|
||||
--- !u!43 &1274430585
|
||||
Mesh:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -433194,6 +433322,37 @@ Mesh:
|
|||
offset: 0
|
||||
size: 0
|
||||
path:
|
||||
--- !u!1 &2033759572
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 2033759573}
|
||||
m_Layer: 0
|
||||
m_Name: Waypoint 1
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &2033759573
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2033759572}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: -0.679, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 2111293181}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!43 &2033814371
|
||||
Mesh:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -453068,6 +453227,41 @@ Mesh:
|
|||
offset: 0
|
||||
size: 0
|
||||
path:
|
||||
--- !u!1 &2111293180
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 2111293181}
|
||||
m_Layer: 0
|
||||
m_Name: Car waypoints
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &2111293181
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2111293180}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 44.08, y: 20.81, z: 1076.25}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 2033759573}
|
||||
- {fileID: 983262430}
|
||||
- {fileID: 403317236}
|
||||
- {fileID: 457169488}
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1001 &2111628778
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -526660,3 +526854,4 @@ SceneRoots:
|
|||
- {fileID: 52704100}
|
||||
- {fileID: 1404293456}
|
||||
- {fileID: 1273264847}
|
||||
- {fileID: 2111293181}
|
||||
|
|
Loading…
Add table
Reference in a new issue