Compare commits
3 commits
2a0ed5cd67
...
16d5b3faad
Author | SHA1 | Date | |
---|---|---|---|
Mark Joshwel | 16d5b3faad | ||
Sc0rch-thinks | 429b96f0e1 | ||
Sc0rch-thinks | 297ead7a21 |
8
RunningLateGame/Assets/Material.meta
Normal file
8
RunningLateGame/Assets/Material.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: af31566b5077e6045848d15729793e85
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
137
RunningLateGame/Assets/Material/nothing.mat
Normal file
137
RunningLateGame/Assets/Material/nothing.mat
Normal file
|
@ -0,0 +1,137 @@
|
|||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: nothing
|
||||
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords:
|
||||
- _ALPHAPREMULTIPLY_ON
|
||||
- _SURFACE_TYPE_TRANSPARENT
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: 3000
|
||||
stringTagMap:
|
||||
RenderType: Transparent
|
||||
disabledShaderPasses:
|
||||
- DepthOnly
|
||||
- SHADOWCASTER
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BaseMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _SpecGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_Lightmaps:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_LightmapsInd:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_ShadowMasks:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _AlphaClip: 0
|
||||
- _AlphaToMask: 0
|
||||
- _Blend: 0
|
||||
- _BlendModePreserveSpecular: 1
|
||||
- _BumpScale: 1
|
||||
- _ClearCoatMask: 0
|
||||
- _ClearCoatSmoothness: 0
|
||||
- _Cull: 2
|
||||
- _Cutoff: 0.5
|
||||
- _DetailAlbedoMapScale: 1
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 10
|
||||
- _DstBlendAlpha: 10
|
||||
- _EnvironmentReflections: 1
|
||||
- _GlossMapScale: 0
|
||||
- _Glossiness: 0
|
||||
- _GlossyReflections: 0
|
||||
- _Metallic: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.005
|
||||
- _QueueOffset: 0
|
||||
- _ReceiveShadows: 1
|
||||
- _Smoothness: 0
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _SrcBlendAlpha: 1
|
||||
- _Surface: 1
|
||||
- _WorkflowMode: 1
|
||||
- _ZWrite: 0
|
||||
m_Colors:
|
||||
- _BaseColor: {r: 0, g: 0, b: 0, a: 0}
|
||||
- _Color: {r: 0, g: 0, b: 0, a: 0}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
--- !u!114 &8248635986458825645
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 11
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
version: 7
|
8
RunningLateGame/Assets/Material/nothing.mat.meta
Normal file
8
RunningLateGame/Assets/Material/nothing.mat.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c8307bc3f06474c428efb0638b4ee7d4
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
RunningLateGame/Assets/Prefabs/car.fbx
(Stored with Git LFS)
Normal file
BIN
RunningLateGame/Assets/Prefabs/car.fbx
(Stored with Git LFS)
Normal file
Binary file not shown.
109
RunningLateGame/Assets/Prefabs/car.fbx.meta
Normal file
109
RunningLateGame/Assets/Prefabs/car.fbx.meta
Normal file
|
@ -0,0 +1,109 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ea8f4c36c1c70304680c14a8eaa0a194
|
||||
ModelImporter:
|
||||
serializedVersion: 22200
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
materials:
|
||||
materialImportMode: 0
|
||||
materialName: 0
|
||||
materialSearch: 1
|
||||
materialLocation: 1
|
||||
animations:
|
||||
legacyGenerateAnimations: 4
|
||||
bakeSimulation: 0
|
||||
resampleCurves: 1
|
||||
optimizeGameObjects: 0
|
||||
removeConstantScaleCurves: 0
|
||||
motionNodeName:
|
||||
rigImportErrors:
|
||||
rigImportWarnings:
|
||||
animationImportErrors:
|
||||
animationImportWarnings:
|
||||
animationRetargetingWarnings:
|
||||
animationDoRetargetingWarnings: 0
|
||||
importAnimatedCustomProperties: 0
|
||||
importConstraints: 0
|
||||
animationCompression: 1
|
||||
animationRotationError: 0.5
|
||||
animationPositionError: 0.5
|
||||
animationScaleError: 0.5
|
||||
animationWrapMode: 0
|
||||
extraExposedTransformPaths: []
|
||||
extraUserProperties: []
|
||||
clipAnimations: []
|
||||
isReadable: 0
|
||||
meshes:
|
||||
lODScreenPercentages: []
|
||||
globalScale: 1
|
||||
meshCompression: 0
|
||||
addColliders: 1
|
||||
useSRGBMaterialColor: 1
|
||||
sortHierarchyByName: 1
|
||||
importPhysicalCameras: 1
|
||||
importVisibility: 1
|
||||
importBlendShapes: 1
|
||||
importCameras: 1
|
||||
importLights: 1
|
||||
nodeNameCollisionStrategy: 1
|
||||
fileIdsGeneration: 2
|
||||
swapUVChannels: 0
|
||||
generateSecondaryUV: 1
|
||||
useFileUnits: 1
|
||||
keepQuads: 0
|
||||
weldVertices: 1
|
||||
bakeAxisConversion: 0
|
||||
preserveHierarchy: 0
|
||||
skinWeightsMode: 0
|
||||
maxBonesPerVertex: 4
|
||||
minBoneWeight: 0.001
|
||||
optimizeBones: 1
|
||||
meshOptimizationFlags: -1
|
||||
indexFormat: 0
|
||||
secondaryUVAngleDistortion: 8
|
||||
secondaryUVAreaDistortion: 15.000001
|
||||
secondaryUVHardAngle: 88
|
||||
secondaryUVMarginMethod: 1
|
||||
secondaryUVMinLightmapResolution: 40
|
||||
secondaryUVMinObjectScale: 1
|
||||
secondaryUVPackMargin: 4
|
||||
useFileScale: 1
|
||||
strictVertexDataChecks: 0
|
||||
tangentSpace:
|
||||
normalSmoothAngle: 60
|
||||
normalImportMode: 0
|
||||
tangentImportMode: 3
|
||||
normalCalculationMode: 4
|
||||
legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes: 0
|
||||
blendShapeNormalImportMode: 1
|
||||
normalSmoothingSource: 0
|
||||
referencedClips: []
|
||||
importAnimation: 1
|
||||
humanDescription:
|
||||
serializedVersion: 3
|
||||
human: []
|
||||
skeleton: []
|
||||
armTwist: 0.5
|
||||
foreArmTwist: 0.5
|
||||
upperLegTwist: 0.5
|
||||
legTwist: 0.5
|
||||
armStretch: 0.05
|
||||
legStretch: 0.05
|
||||
feetSpacing: 0
|
||||
globalScale: 1
|
||||
rootMotionBoneName:
|
||||
hasTranslationDoF: 0
|
||||
hasExtraRoot: 0
|
||||
skeletonHasParents: 1
|
||||
lastHumanDescriptionAvatarSource: {instanceID: 0}
|
||||
autoGenerateAvatarMappingIfUnspecified: 1
|
||||
animationType: 2
|
||||
humanoidOversampling: 1
|
||||
avatarSetup: 0
|
||||
addHumanoidExtraRootOnlyWhenUsingAvatar: 1
|
||||
importBlendShapeDeformPercent: 1
|
||||
remapMaterialsIfMaterialImportModeIsNone: 0
|
||||
additionalBone: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
3155
RunningLateGame/Assets/Prefabs/player.prefab
Normal file
3155
RunningLateGame/Assets/Prefabs/player.prefab
Normal file
File diff suppressed because it is too large
Load diff
7
RunningLateGame/Assets/Prefabs/player.prefab.meta
Normal file
7
RunningLateGame/Assets/Prefabs/player.prefab.meta
Normal file
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fede53ad5812a1046bf12a85cacb875a
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load diff
Binary file not shown.
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8237b59589e7d0f43920c1a2f5ae94f8
|
||||
guid: c5b15e08603268b499e9f7d38414aa1b
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 23800000
|
Binary file not shown.
|
@ -1,92 +1,133 @@
|
|||
/*
|
||||
* author: lin hengrui ryan
|
||||
* date: 30/7/2024
|
||||
* description: ai code for the different ai in the game
|
||||
* description: AI code for the different AI in the game
|
||||
*/
|
||||
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
using Random = System.Random;
|
||||
|
||||
public class AI : MonoBehaviour
|
||||
{
|
||||
public enum EntityType
|
||||
{
|
||||
Human,
|
||||
Car
|
||||
};
|
||||
|
||||
public EntityType entityType;
|
||||
public LayerMask walkableLayers;
|
||||
private NavMeshAgent _agent;
|
||||
private Animator _animator;
|
||||
private string _currentState;
|
||||
private string _nextState;
|
||||
/// <summary>
|
||||
/// to save resources when referring to the speed of this AI if its human
|
||||
/// </summary>
|
||||
private static readonly int AnimatorSpeed = Animator.StringToHash("Speed");
|
||||
private bool _walkPointSet;
|
||||
public Vector3 walkPoint;
|
||||
public int strollRange;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// set the layers the AI can be on
|
||||
/// </summary>
|
||||
public LayerMask walkableLayers;
|
||||
|
||||
/// <summary>
|
||||
/// the destination coordinate of the AI
|
||||
/// </summary>
|
||||
public Vector3 destinationCoord;
|
||||
|
||||
/// <summary>
|
||||
/// the range that the AI can set as their destination
|
||||
/// </summary>
|
||||
public int movingRange;
|
||||
|
||||
/// <summary>
|
||||
/// the nav mash agent that is on this AI
|
||||
/// </summary>
|
||||
private NavMeshAgent _agent;
|
||||
|
||||
/// <summary>
|
||||
/// the animator that is attached to this AI if applicable
|
||||
/// </summary>
|
||||
private Animator _animator;
|
||||
|
||||
/// <summary>
|
||||
/// the current state that the AI is at this point in time
|
||||
/// </summary>
|
||||
private string _currentState;
|
||||
|
||||
/// <summary>
|
||||
/// a bool to check if the destination point is set
|
||||
/// </summary>
|
||||
private bool _destinationPointSet;
|
||||
|
||||
/// <summary>
|
||||
/// the state that the AI will be on the next update
|
||||
/// </summary>
|
||||
private string _nextState;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// to set initial values
|
||||
/// </summary>
|
||||
public void Awake()
|
||||
{
|
||||
_animator = GetComponent<Animator>();
|
||||
_currentState = "Strolling";
|
||||
|
||||
|
||||
_agent = GetComponent<NavMeshAgent>();
|
||||
if (entityType == EntityType.Human)
|
||||
{
|
||||
_animator = GetComponent<Animator>();
|
||||
_currentState = "Strolling";
|
||||
StartCoroutine(Strolling());
|
||||
}
|
||||
_animator = GetComponent<Animator>();
|
||||
_currentState = "Strolling";
|
||||
|
||||
|
||||
_nextState = _currentState;
|
||||
ChangeState();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// to update the speed of the AI to the animator each frame and to update any state changes to the AI
|
||||
/// </summary>
|
||||
public void Update()
|
||||
{
|
||||
if (entityType == EntityType.Human)
|
||||
{
|
||||
_animator.SetFloat(AnimatorSpeed, _agent.velocity.magnitude);
|
||||
}
|
||||
_animator.SetFloat(AnimatorSpeed, _agent.velocity.magnitude);
|
||||
_currentState = _nextState;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// to change the scene when needed
|
||||
/// </summary>
|
||||
private void ChangeState()
|
||||
{
|
||||
StartCoroutine(_currentState);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// to set a random x and y coordinate for the AI to go to
|
||||
/// </summary>
|
||||
private void SearchWalkPoint()
|
||||
{
|
||||
var rand = new Random();
|
||||
float randomX = rand.Next(-strollRange * 100, strollRange * 100);
|
||||
float randomZ = rand.Next(-strollRange * 100, strollRange * 100);
|
||||
walkPoint = new Vector3(
|
||||
transform.position.x + (randomX / 100),
|
||||
float randomX = rand.Next(-movingRange * 100, movingRange * 100);
|
||||
float randomZ = rand.Next(-movingRange * 100, movingRange * 100);
|
||||
destinationCoord = new Vector3(
|
||||
transform.position.x + randomX / 100,
|
||||
transform.position.y,
|
||||
transform.position.z + (randomZ / 100)
|
||||
transform.position.z + randomZ / 100
|
||||
);
|
||||
if (Physics.Raycast(walkPoint, -transform.up, 2f, walkableLayers))
|
||||
{
|
||||
_walkPointSet = true;
|
||||
}
|
||||
if (Physics.Raycast(destinationCoord, -transform.up, 2f, walkableLayers)) _destinationPointSet = true;
|
||||
}
|
||||
|
||||
IEnumerator Strolling()
|
||||
/// <summary>
|
||||
/// a state that the AI wonders around using the SearchWalkPoint function to find a location for the AI to go to
|
||||
/// </summary>
|
||||
private IEnumerator Strolling()
|
||||
{
|
||||
SearchWalkPoint();
|
||||
|
||||
|
||||
while (_currentState == "Strolling")
|
||||
{
|
||||
Debug.Log("strolling");
|
||||
if (!_walkPointSet)
|
||||
{
|
||||
if (!_destinationPointSet)
|
||||
SearchWalkPoint();
|
||||
}
|
||||
else
|
||||
{
|
||||
_agent.SetDestination((walkPoint));
|
||||
}
|
||||
_agent.SetDestination(destinationCoord);
|
||||
|
||||
if ((transform.position - walkPoint).magnitude < 1f)
|
||||
{
|
||||
_walkPointSet = false;
|
||||
}
|
||||
if ((transform.position - destinationCoord).magnitude < 1f) _destinationPointSet = false;
|
||||
|
||||
yield return new WaitForSeconds(1F);
|
||||
yield return new WaitForSeconds(1f);
|
||||
}
|
||||
|
||||
ChangeState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
66
RunningLateGame/Assets/Scripts/CarController.cs
Normal file
66
RunningLateGame/Assets/Scripts/CarController.cs
Normal file
|
@ -0,0 +1,66 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CarController : MonoBehaviour
|
||||
{
|
||||
public enum Axel
|
||||
{
|
||||
Front,
|
||||
Rear
|
||||
}
|
||||
|
||||
public float acceleration;
|
||||
public float turnAngle;
|
||||
public List<Wheel> wheels;
|
||||
|
||||
public float brakeForce;
|
||||
public bool braking;
|
||||
private float _currentAcceleration;
|
||||
private float _currentTurn;
|
||||
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
Move();
|
||||
Steering();
|
||||
Brake();
|
||||
}
|
||||
|
||||
public void SetInputs(float forwardAmount, float turnAmount)
|
||||
{
|
||||
_currentAcceleration = forwardAmount * acceleration;
|
||||
_currentTurn = turnAmount * turnAngle;
|
||||
}
|
||||
|
||||
|
||||
public void Move()
|
||||
{
|
||||
foreach (var wheel in wheels) wheel.wheelCollider.motorTorque = _currentAcceleration;
|
||||
}
|
||||
|
||||
public void Brake()
|
||||
{
|
||||
if (braking)
|
||||
foreach (var wheel in wheels)
|
||||
wheel.wheelCollider.brakeTorque = brakeForce;
|
||||
else
|
||||
foreach (var wheel in wheels)
|
||||
wheel.wheelCollider.brakeTorque = 0f;
|
||||
}
|
||||
|
||||
public void Steering()
|
||||
{
|
||||
foreach (var wheel in wheels)
|
||||
if (wheel.axel == Axel.Front)
|
||||
wheel.wheelCollider.steerAngle = _currentTurn;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct Wheel
|
||||
{
|
||||
public GameObject wheelModel;
|
||||
public WheelCollider wheelCollider;
|
||||
public Axel axel;
|
||||
}
|
||||
}
|
11
RunningLateGame/Assets/Scripts/CarController.cs.meta
Normal file
11
RunningLateGame/Assets/Scripts/CarController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6da9430305b32f446a2517f4a73fdf57
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
114
RunningLateGame/Assets/Scripts/ai car.cs
Normal file
114
RunningLateGame/Assets/Scripts/ai car.cs
Normal file
|
@ -0,0 +1,114 @@
|
|||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class AICar : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Transform carPosition;
|
||||
[SerializeField] private float stoppingDistance;
|
||||
[SerializeField] private float slowingSpeed;
|
||||
[SerializeField] private float slowingDistance;
|
||||
[SerializeField] private float reverseDist;
|
||||
private CarController _car;
|
||||
private string _currentState;
|
||||
private Transform _driveTarget;
|
||||
private string _nextState;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
var hasChild = false;
|
||||
var i = 0;
|
||||
GameObject test;
|
||||
while (!hasChild)
|
||||
{
|
||||
test = gameObject.transform.GetChild(i).gameObject;
|
||||
if (test.name == "Target")
|
||||
{
|
||||
_driveTarget = test.transform;
|
||||
hasChild = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
_car = GetComponent<CarController>();
|
||||
_currentState = "Driving";
|
||||
_nextState = _currentState;
|
||||
ChangeState();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
_currentState = _nextState;
|
||||
}
|
||||
|
||||
private void ChangeState()
|
||||
{
|
||||
StartCoroutine(_currentState);
|
||||
}
|
||||
|
||||
private IEnumerator Driving()
|
||||
{
|
||||
_car = GetComponent<CarController>();
|
||||
|
||||
while (_currentState == "Driving")
|
||||
{
|
||||
var accelerationAmount = 0f;
|
||||
var turnAmount = 0f;
|
||||
var targetPosition = _driveTarget.position;
|
||||
var dirToMove = (targetPosition - carPosition.transform.position).normalized;
|
||||
var forwardsAmount = Vector3.Dot(carPosition.transform.forward, dirToMove);
|
||||
var directionToDrive = Vector3.SignedAngle(carPosition.transform.forward, dirToMove, Vector3.up);
|
||||
var distanceToTarget = Vector3.Distance(carPosition.position, targetPosition);
|
||||
if (distanceToTarget >= stoppingDistance)
|
||||
{
|
||||
_car.braking = false;
|
||||
//in front of target position
|
||||
if (forwardsAmount > 0)
|
||||
{
|
||||
//closer than the slowing distance
|
||||
if (distanceToTarget <= slowingDistance)
|
||||
{
|
||||
//the car is very fast
|
||||
if (carPosition.GetComponent<Rigidbody>().velocity.magnitude > slowingSpeed)
|
||||
accelerationAmount = -2;
|
||||
else
|
||||
accelerationAmount = 1;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
accelerationAmount = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (distanceToTarget < reverseDist)
|
||||
accelerationAmount = -1;
|
||||
else
|
||||
accelerationAmount = 1;
|
||||
}
|
||||
|
||||
|
||||
if (directionToDrive < 0)
|
||||
turnAmount = 1;
|
||||
else if (directionToDrive > 0)
|
||||
turnAmount = -1;
|
||||
else
|
||||
turnAmount = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_car.braking = true;
|
||||
accelerationAmount = 0f;
|
||||
turnAmount = 0f;
|
||||
}
|
||||
|
||||
Debug.Log(carPosition.GetComponent<Rigidbody>().velocity.magnitude);
|
||||
_car.SetInputs(accelerationAmount, turnAmount);
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
}
|
||||
}
|
3
RunningLateGame/Assets/Scripts/ai car.cs.meta
Normal file
3
RunningLateGame/Assets/Scripts/ai car.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bc82a40176164f02897928bd573bc2ca
|
||||
timeCreated: 1722499203
|
|
@ -32,7 +32,7 @@ Material:
|
|||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
m_CustomRenderQueue: 2000
|
||||
stringTagMap:
|
||||
RenderType: Opaque
|
||||
disabledShaderPasses:
|
||||
|
@ -137,4 +137,3 @@ Material:
|
|||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
m_AllowLocking: 1
|
||||
|
|
|
@ -17,15 +17,25 @@ MonoBehaviour:
|
|||
m_MaterialReferences: []
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Heather
|
||||
m_Shader: {fileID: -6465566751694194690, guid: dfa3b96612ed4df4a97b7fd06217ba23, type: 3}
|
||||
m_ShaderKeywords: _ALPHATEST_ON _BUILTIN_ALPHATEST_ON _BUILTIN_AlphaClip _DISABLE_DECALS
|
||||
_DISABLE_SSR _DISABLE_SSR_TRANSPARENT _DOUBLESIDED_ON
|
||||
m_Shader: {fileID: -6465566751694194690, guid: dfa3b96612ed4df4a97b7fd06217ba23,
|
||||
type: 3}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords:
|
||||
- _ALPHATEST_ON
|
||||
- _BUILTIN_ALPHATEST_ON
|
||||
- _BUILTIN_AlphaClip
|
||||
- _DISABLE_DECALS
|
||||
- _DISABLE_SSR
|
||||
- _DISABLE_SSR_TRANSPARENT
|
||||
- _DOUBLESIDED_ON
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 2
|
||||
m_EnableInstancingVariants: 1
|
||||
m_DoubleSidedGI: 1
|
||||
|
@ -40,6 +50,7 @@ Material:
|
|||
- RayTracingPrepass
|
||||
- ForwardEmissiveForDeferred
|
||||
- MOTIONVECTORS
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
|
@ -56,11 +67,13 @@ Material:
|
|||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- TerrainTexture:
|
||||
m_Texture: {fileID: 707188533860266558, guid: dfce0fe87ba57ef449f748baa61f1cc2, type: 2}
|
||||
m_Texture: {fileID: 707188533860266558, guid: dfce0fe87ba57ef449f748baa61f1cc2,
|
||||
type: 2}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- Terrain_Splatmap:
|
||||
m_Texture: {fileID: 707188533860266558, guid: dfce0fe87ba57ef449f748baa61f1cc2, type: 2}
|
||||
m_Texture: {fileID: 707188533860266558, guid: dfce0fe87ba57ef449f748baa61f1cc2,
|
||||
type: 2}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- Terrain_Splatmap_0:
|
||||
|
@ -68,7 +81,8 @@ Material:
|
|||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- Terrain_Splatmap_1:
|
||||
m_Texture: {fileID: 6456901915053530685, guid: dfce0fe87ba57ef449f748baa61f1cc2, type: 2}
|
||||
m_Texture: {fileID: 6456901915053530685, guid: dfce0fe87ba57ef449f748baa61f1cc2,
|
||||
type: 2}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- Texture2D_8713F080:
|
||||
|
@ -159,7 +173,7 @@ Material:
|
|||
- _AlphaCutoffEnable: 1
|
||||
- _AlphaDstBlend: 0
|
||||
- _AlphaSrcBlend: 1
|
||||
- _AlphaToMask: 0
|
||||
- _AlphaToMask: 1
|
||||
- _AlphaToMaskInspectorValue: 0
|
||||
- _BUILTIN_AlphaClip: 1
|
||||
- _BUILTIN_Blend: 0
|
||||
|
@ -174,6 +188,7 @@ Material:
|
|||
- _BUILTIN_ZWriteControl: 0
|
||||
- _Blend: 0
|
||||
- _BlendMode: 0
|
||||
- _BlendModePreserveSpecular: 0
|
||||
- _CastShadows: 1
|
||||
- _ConservativeDepthOffsetEnable: 0
|
||||
- _Cull: 0
|
||||
|
@ -188,6 +203,7 @@ Material:
|
|||
- _DstBlend: 0
|
||||
- _EnableBlendModePreserveSpecularLighting: 1
|
||||
- _EnableFogOnTransparent: 1
|
||||
- _ExcludeFromTUAndAA: 0
|
||||
- _FadeBias: 1
|
||||
- _ForceForwardEmissive: 0
|
||||
- _OpaqueCullMode: 2
|
||||
|
@ -232,7 +248,8 @@ Material:
|
|||
- use_terrain_texture: 0
|
||||
m_Colors:
|
||||
- Color_1: {r: 1, g: 1, b: 1, a: 0}
|
||||
- Color_5108e9ce42374b88877d5b6d32008f57: {r: 0.4245283, g: 0.3904859, b: 0.3224012, a: 1}
|
||||
- Color_5108e9ce42374b88877d5b6d32008f57: {r: 0.4245283, g: 0.3904859, b: 0.3224012,
|
||||
a: 1}
|
||||
- Color_98d740f37ee94393862968e06dd248d6: {r: 1, g: 1, b: 1, a: 0}
|
||||
- Fade_Color: {r: 0, g: 0, b: 0, a: 0}
|
||||
- SplatA: {r: 0, g: 0, b: 0, a: 1}
|
||||
|
@ -245,8 +262,10 @@ Material:
|
|||
- Terrain_Scale: {r: 100, g: 100, b: 0, a: 0}
|
||||
- Vector2_1a286d49dc7b437fb4f1ea99b04e2664: {r: 0.05, g: 0.5, b: 0, a: 0}
|
||||
- Vector2_98F9C2DA: {r: 0.2, g: 0.2, b: 0, a: 0}
|
||||
- _DiffusionProfileAsset: {r: -0.00000002060262, g: 7.3194675e-27, b: 69972056, a: -3.7115523e+9}
|
||||
- _Diffusion_Profile_Asset: {r: -0.00000002060262, g: 7.3194675e-27, b: 69972056, a: -3.7115523e+9}
|
||||
- _DiffusionProfileAsset: {r: -0.00000002060262, g: 7.3194675e-27, b: 69972056,
|
||||
a: -3.7115523e+9}
|
||||
- _Diffusion_Profile_Asset: {r: -0.00000002060262, g: 7.3194675e-27, b: 69972056,
|
||||
a: -3.7115523e+9}
|
||||
- _DoubleSidedConstants: {r: 1, g: 1, b: -1, a: 0}
|
||||
- _EmissionColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _SSSColor: {r: 0.95744157, g: 1, b: 0.5424528, a: 0}
|
||||
|
|
|
@ -12,13 +12,14 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: b2686e09ec7aef44bad2843e4416f057, type: 3}
|
||||
m_Name: FoliageDiffusionProfile
|
||||
m_EditorClassIdentifier:
|
||||
m_Version: 1
|
||||
profile:
|
||||
scatteringDistance: {r: 0.7568628, g: 0.7019608, b: 0.24313727, a: 1}
|
||||
scatteringDistance: {r: 0.7490196, g: 0.69468653, b: 0.24061768, a: 1}
|
||||
scatteringDistanceMultiplier: 1.0104713
|
||||
transmissionTint: {r: 1, g: 1, b: 1, a: 1}
|
||||
texturingMode: 0
|
||||
transmissionMode: 1
|
||||
thicknessRemap: {x: 0, y: 0.2873168}
|
||||
worldScale: 1
|
||||
ior: 1.4
|
||||
hash: 1081692787
|
||||
hash: 1074823563
|
||||
m_Version: 2
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
--- !u!78 &1
|
||||
TagManager:
|
||||
serializedVersion: 2
|
||||
tags: []
|
||||
tags:
|
||||
- CinemachineTarget
|
||||
layers:
|
||||
- Default
|
||||
- TransparentFX
|
||||
|
@ -11,7 +12,7 @@ TagManager:
|
|||
-
|
||||
- Water
|
||||
- UI
|
||||
-
|
||||
- Player
|
||||
-
|
||||
-
|
||||
-
|
||||
|
|
Reference in a new issue