made environment for BensonV4

This commit is contained in:
2024-04-19 11:30:12 +02:00
parent 92a98b98d7
commit 769315be1e
21 changed files with 1553 additions and 435 deletions

Binary file not shown.

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: d616899359e594c45a68f837475f54bb
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 683b6cb6d0a474744822c888b46772c9, type: 3}
optimizeModel: 1
forceArbitraryBatchSize: 1
treatErrorsAsWarnings: 0
importMode: 1
weightsTypeMode: 0
activationTypeMode: 0

View File

@@ -1,104 +0,0 @@
using UnityEditor;
using UnityEngine;
public class WelcomeWindow : EditorWindow
{
private GUIStyle textureButton;
private GUIStyle headingText;
private GUIStyle commonText;
private Texture2D top;
private Texture2D image1;
private Texture2D linkButton;
private Texture2D logo;
private Vector2 scrollIndex;
[UnityEditor.Callbacks.DidReloadScripts]
private static void OpenWindowOnUnityStart()
{
if (EditorApplication.isPlayingOrWillChangePlaymode)
return;
OpenWindow();
}
[MenuItem("Tools/EmaceArt/Welcome Window")]
private static void OpenWindow()
{
EditorWindow panel = GetWindow<WelcomeWindow>();
panel.titleContent = new GUIContent("Hello Developer!", Resources.Load<Texture2D>("Favi_top"));
// panel.minSize = new Vector2(600, Mathf.Min(Screen.currentResolution.height, 862));
// panel.maxSize = new Vector2(600, Mathf.Min(Screen.currentResolution.height, 862));
//panel.ShowUtility();
}
private void OnEnable()
{
var style = Resources.Load<GUISkin>("GUISkin");
textureButton = style.GetStyle("textureButton");
headingText = style.GetStyle("headingText");
commonText = style.GetStyle("commonText");
top = Resources.Load<Texture2D>("EA_Top");
image1 = Resources.Load<Texture2D>("Btn_01");
linkButton = Resources.Load<Texture2D>("button_free_zone");
logo = Resources.Load<Texture2D>("Logo");
}
private void OnGUI()
{
scrollIndex = GUILayout.BeginScrollView(scrollIndex);
GUILayout.BeginVertical();
DrawHeader();
GUILayout.Space(20f);
DrawBody();
GUILayout.Space(20f);
DrawFooter();
GUILayout.EndVertical();
GUILayout.EndScrollView();
}
private void DrawHeader()
{
if (GUILayout.Button(top, textureButton))
Application.OpenURL("https://assetstore.unity.com/packages/3d/environments/fantasy/slavic-medieval-village-town-interior-and-exterior-pack-environm-137794");
}
private void DrawBody()
{
GUILayout.Label("Thanks for checkin Slavica Lite", headingText);
GUILayout.Space(1f);
GUILayout.Label("This pack perfect match with the Medieval Slavica Town Full!", commonText);
GUILayout.Space(20f);
if (GUILayout.Button(image1, textureButton))
Application.OpenURL("https://assetstore.unity.com/packages/3d/environments/fantasy/slavic-medieval-village-town-interior-and-exterior-pack-environm-137794");
}
private void DrawFooter()
{
GUILayout.BeginHorizontal();
if (GUILayout.Button(logo, textureButton))
Application.OpenURL("https://www.emaceart.com");
GUILayout.BeginVertical();
GUILayout.Space(10f);
GUILayout.Label("Visit my free zone. If you like this content, don't forget leave review :)", commonText);
GUILayout.Space(10f);
if (GUILayout.Button(linkButton, textureButton))
Application.OpenURL("https://assetstore.unity.com/lists/free-zone-178789");
GUILayout.EndVertical();
GUILayout.EndHorizontal();
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 15e5888e5fc5cbe4cbe94ecca9240790
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,6 +0,0 @@
Thanks for download!
This pack of assets belongs to my other huge pack, which I encourage to buy!
https://assetstore.unity.com/packages/3d/environments/fantasy/slavic-medieval-village-town-interior-and-exterior-pack-environm-137794
If you have any questions, or request of additional models, fell free to email me at CONTACT@EMACEART.COM

View File

@@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 3c85e6a8b5d07b545988a6efab51a32e
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 4fa517224fb5c15469ddaafdf4a94068
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: d884527f3e242c144af52b11faf49d2f
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1 +1 @@
{"count":1,"self":309.6612096,"total":311.8317685,"children":{"InitializeActuators":{"count":1,"self":0.0015026999999999998,"total":0.0015026999999999998,"children":null},"InitializeSensors":{"count":1,"self":0.0020054,"total":0.0020054,"children":null},"AgentSendState":{"count":15319,"self":1.2925794,"total":1.8818713,"children":{"CollectObservations":{"count":15319,"self":0.3923006,"total":0.3923006,"children":null},"WriteActionMask":{"count":15319,"self":0.0248735,"total":0.0248735,"children":null},"RequestDecision":{"count":15319,"self":0.085557,"total":0.1400864,"children":{"RayPerceptionSensor.Perceive":{"count":30638,"self":0.0545294,"total":0.0545294,"children":null}}},"RayPerceptionSensor.Perceive":{"count":30636,"self":0.0320314,"total":0.0320314,"children":null}}},"DecideAction":{"count":15319,"self":0.0765185,"total":0.0765185,"children":null},"AgentAct":{"count":15319,"self":0.2076653,"total":0.2076653,"children":{"RayPerceptionSensor.Perceive":{"count":36,"self":0,"total":0,"children":null}}}},"gauges":{"BensonImitationV3.CumulativeReward":{"count":9,"max":24.016304,"min":7.681255,"runningAverage":20.2167473,"value":23.9503059,"weightedAverage":21.3022}},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1712925366","unity_version":"2022.3.11f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2022.3.11f1\\Editor\\Unity.exe -projectpath C:\\Users\\noahk\\Documents\\Unity projects\\Racesm -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-noahk -hubSessionId 9ca26982-a0f6-4127-8a14-962f9b9ca2ae -accessToken Uz6Elw7wQ8JPvtO_g14OUcqdUTEXpflxltMduak3nKQ005f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"AI training","end_time_seconds":"1712925678"}} {"count":1,"self":24.879729599999997,"total":25.3807673,"children":{"InitializeActuators":{"count":1,"self":0.0015030999999999998,"total":0.0015030999999999998,"children":null},"InitializeSensors":{"count":1,"self":0.002506,"total":0.002506,"children":null},"AgentSendState":{"count":1033,"self":0.052233499999999995,"total":0.46367749999999996,"children":{"CollectObservations":{"count":1033,"self":0.39369149999999997,"total":0.39369149999999997,"children":null},"WriteActionMask":{"count":1033,"self":0.0035231,"total":0.0035231,"children":null},"RequestDecision":{"count":1033,"self":0.0105981,"total":0.0142294,"children":{"RayPerceptionSensor.Perceive":{"count":2066,"self":0.0036312999999999996,"total":0.0036312999999999996,"children":null}}}}},"DecideAction":{"count":1033,"self":0.0070783999999999994,"total":0.0070783999999999994,"children":null},"AgentAct":{"count":1033,"self":0.0257575,"total":0.0257575,"children":{"RayPerceptionSensor.Perceive":{"count":2,"self":0,"total":0,"children":null}}}},"gauges":{"BensonV4.CumulativeReward":{"count":1,"max":23.1291828,"min":23.1291828,"runningAverage":23.1291828,"value":23.1291828,"weightedAverage":23.1291828}},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1713518767","unity_version":"2022.3.11f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2022.3.11f1\\Editor\\Unity.exe -projectpath C:\\Users\\noahk\\Documents\\Unity projects\\Racesm -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-noahk -hubSessionId 4068a663-bd5e-4526-907d-88111baad304 -accessToken lEnHrjqkaCSQA7MdFiPPC8yoqdYZh4_FAtRTqZKLQPI005f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"AI training","end_time_seconds":"1713518792"}}

View File

@@ -1,6 +1,6 @@
%YAML 1.1 %YAML 1.1
%TAG !u! tag:unity3d.com,2011: %TAG !u! tag:unity3d.com,2011:
--- !u!1 &3959557473817272857 --- !u!1 &7234834637752836426
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
@@ -8,47 +8,48 @@ GameObject:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 257965083965449723} - component: {fileID: 1288577159706020061}
- component: {fileID: 2670097205243573776} - component: {fileID: 471271415023977368}
- component: {fileID: 5347261225699996736} - component: {fileID: 1915818325675539370}
- component: {fileID: 8320126915491364009} - component: {fileID: 3466260334280045808}
- component: {fileID: 5655726606384773670}
m_Layer: 0 m_Layer: 0
m_Name: model m_Name: CheckPoint
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 1
--- !u!4 &257965083965449723 --- !u!4 &1288577159706020061
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3959557473817272857} m_GameObject: {fileID: 7234834637752836426}
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068} m_LocalRotation: {x: 0.7071068, y: -0, z: -0, w: 0.7071068}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 30, y: 1, z: 30} m_LocalScale: {x: 7.5, y: 0.25, z: 7.5}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
m_Father: {fileID: 1288577159706020061} m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
--- !u!33 &2670097205243573776 --- !u!33 &471271415023977368
MeshFilter: MeshFilter:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3959557473817272857} m_GameObject: {fileID: 7234834637752836426}
m_Mesh: {fileID: 10206, guid: 0000000000000000e000000000000000, type: 0} m_Mesh: {fileID: 10206, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &5347261225699996736 --- !u!23 &1915818325675539370
MeshRenderer: MeshRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3959557473817272857} m_GameObject: {fileID: 7234834637752836426}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 1
m_ReceiveShadows: 1 m_ReceiveShadows: 1
@@ -84,13 +85,13 @@ MeshRenderer:
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 0 m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0} m_AdditionalVertexStreams: {fileID: 0}
--- !u!65 &8320126915491364009 --- !u!65 &3466260334280045808
BoxCollider: BoxCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3959557473817272857} m_GameObject: {fileID: 7234834637752836426}
m_Material: {fileID: 0} m_Material: {fileID: 0}
m_IncludeLayers: m_IncludeLayers:
serializedVersion: 2 serializedVersion: 2
@@ -105,35 +106,16 @@ BoxCollider:
serializedVersion: 3 serializedVersion: 3
m_Size: {x: 1.0000001, y: 2.0000005, z: 1.0000005} m_Size: {x: 1.0000001, y: 2.0000005, z: 1.0000005}
m_Center: {x: 0.000000059604645, y: 0, z: -0.00000008940699} m_Center: {x: 0.000000059604645, y: 0, z: -0.00000008940699}
--- !u!1 &7234834637752836426 --- !u!114 &5655726606384773670
GameObject: MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1288577159706020061}
m_Layer: 0
m_Name: CheckPoint
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1288577159706020061
Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7234834637752836426} m_GameObject: {fileID: 7234834637752836426}
serializedVersion: 2 m_Enabled: 1
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_EditorHideFlags: 0
m_LocalPosition: {x: 48.319576, y: 2.6632206, z: -37.745872} m_Script: {fileID: 11500000, guid: 5cb7e797faf91a145ace5b3e5953a682, type: 3}
m_LocalScale: {x: 1, y: 1, z: 1} m_Name:
m_ConstrainProportionsScale: 0 m_EditorClassIdentifier:
m_Children: isCollected: 0
- {fileID: 257965083965449723}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 9b8c300fd72328743893f6c3a05071cc guid: dd1c964ebcc644242b0798f3cdc71e51
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

File diff suppressed because it is too large Load Diff

View File

@@ -115,6 +115,9 @@ public class AgentController : Agent
public override void OnActionReceived(ActionBuffers actions) public override void OnActionReceived(ActionBuffers actions)
{ {
print("L");
// Actions size = 2 [vertical speed, horizontal speed] = [-1..1, -1..1] // discrete = [{0, 1, 2}, {0, 1, 2}] = [{-1, 0, 1}...] // Actions size = 2 [vertical speed, horizontal speed] = [-1..1, -1..1] // discrete = [{0, 1, 2}, {0, 1, 2}] = [{-1, 0, 1}...]
float vInput = 0; float vInput = 0;
float hInput = 0; float hInput = 0;
@@ -133,7 +136,7 @@ public class AgentController : Agent
if (vInput == 1f) if (vInput == 1f)
{ {
AddReward(0.001f); AddReward(0.02f);
} }
// give benson mental pain for existing (punishment for maximizing first checkpoint by standing still) // give benson mental pain for existing (punishment for maximizing first checkpoint by standing still)

View File

@@ -0,0 +1,226 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.Actuators;
using UnityEngine.UIElements;
using System.Linq;
using Unity.Mathematics;
using Unity.VisualScripting;
using System.Reflection;
using System;
public class AgentControllerV4 : Agent
{
public float motorForce = 300;
public float brakeForce = 500;
public float maxSpeed = 400;
public float steeringRange = 9;
Rigidbody rigidBody;
public List<GameObject> checkpoints;
Vector3 startPosition;
Quaternion startRotation;
int currentStep = 0;
int stepsSinceCheckpoint = 0;
public int maxStepsPerCheckpoint = 300;
public int distanceBetweenCheckpoints;
// Start is called before the first frame update
void Start()
{
rigidBody = GetComponent<Rigidbody>();
// Find all child GameObjects that have the WheelControl script attached
startPosition = transform.localPosition;
startRotation = transform.localRotation;
}
public override void OnEpisodeBegin()
{
stepsSinceCheckpoint = 0;
// reset car
transform.localPosition = startPosition;
transform.localRotation = startRotation;
rigidBody.velocity = Vector3.zero;
rigidBody.angularVelocity = Vector3.zero;
// reset checkpoints
foreach (GameObject checkpoint in checkpoints)
{
checkpoint.GetComponent<Checkpoint>().isCollected = false;
}
}
public override void CollectObservations(VectorSensor sensor)
{
Transform currentCheckpoint = checkpoints[0].transform;
foreach (GameObject checkpoint in checkpoints)
{
bool isCollected = checkpoint.GetComponent<Checkpoint>().isCollected;
if (!isCollected)
{
currentCheckpoint = checkpoint.transform;
break;
}
}
print(transform.rotation.y);
sensor.AddObservation(transform.rotation.y);
Vector3 position = transform.localPosition;
Vector3 checkpointPosition = currentCheckpoint.localPosition;
Vector2 toCheckpoint = new Vector2(
checkpointPosition.x - position.x,
checkpointPosition.z - position.z
);
sensor.AddObservation(toCheckpoint.normalized);
sensor.AddObservation(toCheckpoint.magnitude);
var FullVelocityMagnitude = rigidBody.velocity.magnitude; // Velocity including angular velocity
var angularMagnitude = rigidBody.angularVelocity.magnitude;
var forwardMagnitude = Mathf.Sqrt( Mathf.Pow(FullVelocityMagnitude, 2) - Mathf.Pow(angularMagnitude, 2)); // Agent velocity in forward direction
if (forwardMagnitude >= 0.001)
sensor.AddObservation(forwardMagnitude);
else
sensor.AddObservation(FullVelocityMagnitude);
sensor.AddObservation(angularMagnitude);
}
public override void OnActionReceived(ActionBuffers actions)
{
// Actions size = 2 [vertical speed, horizontal speed] = [-1..1, -1..1] // discrete = [{0, 1, 2}, {0, 1, 2}] = [{-1, 0, 1}...]
float vInput = 0;
float hInput = 0;
if (actions.DiscreteActions[0] == 0)
vInput = -1f;
if (actions.DiscreteActions[0] == 1)
vInput = 1f;
if (actions.DiscreteActions[1] == 0)
hInput = -1f;
if (actions.DiscreteActions[1] == 1)
hInput = 1f;
// reward for going forward
// if (vInput == 1f)
// {
// AddReward(0.02f);
// }
// give benson mental pain for existing (punishment for maximizing first checkpoint by standing still)
AddReward(-0.002f);
Vector3 movementForce = vInput * motorForce * transform.forward;
float carAngle = transform.rotation.eulerAngles.y + steeringRange * hInput;
float x = transform.rotation.eulerAngles.x;
float z = transform.rotation.eulerAngles.z;
transform.rotation = Quaternion.Euler(x, carAngle, z);
rigidBody.AddForce(movementForce, ForceMode.Impulse);
// rewards
Transform currentCheckpoint = checkpoints[0].transform;
foreach (GameObject checkpoint in checkpoints)
{
bool isCollected = checkpoint.GetComponent<Checkpoint>().isCollected;
if (!isCollected)
{
currentCheckpoint = checkpoint.transform;
break;
}
}
float checkpintDistance = distanceToCheckpoint(currentCheckpoint);
float reward = (1 - Mathf.InverseLerp(0, distanceBetweenCheckpoints, checkpintDistance)) / 1000;
AddReward(reward);
if (checkpintDistance < 0.1f)
{
currentCheckpoint.GetComponent<Checkpoint>().isCollected = true;
stepsSinceCheckpoint = 0;
if (currentCheckpoint == checkpoints[checkpoints.Count - 1].transform)
{
AddReward(10f);
EndEpisode();
}
AddReward(1.0f);
}
currentStep += 1;
stepsSinceCheckpoint += 1;
if (stepsSinceCheckpoint >= maxStepsPerCheckpoint)
{
stepsSinceCheckpoint = 0;
EndEpisode();
}
}
public override void Heuristic(in ActionBuffers actionsOut)
{
var discreteActionsOut = actionsOut.DiscreteActions;
discreteActionsOut[0] = 2;
discreteActionsOut[1] = 2;
if (Input.GetAxis("Vertical") < -0.5)
discreteActionsOut[0] = 0;
if (Input.GetAxis("Vertical") > 0.5)
discreteActionsOut[0] = 1;
if (Input.GetAxis("Horizontal") < -0.5)
discreteActionsOut[1] = 0;
if (Input.GetAxis("Horizontal") > 0.5)
discreteActionsOut[1] = 1;
}
// finds distance from agent to closest point on the checkpoint line
float distanceToCheckpoint(Transform checkpoint)
{
var closestPoint = checkpoint.GetComponent<Collider>().ClosestPointOnBounds(transform.position);
var distanceToCheckpoint = Vector3.Distance(transform.position, closestPoint);
return distanceToCheckpoint;
}
// find angle from agent to middle of checkpoint line.
float angleToCheckpoint(Transform checkpoint)
{
Vector3 checkpointDirection = checkpoint.localPosition - transform.localPosition;
float angle = Vector3.SignedAngle(transform.forward, checkpointDirection, Vector3.up);
return angle;
}
// punishment for hitting a wall
private void OnCollisionEnter(Collision other) {
if (other.gameObject.tag == "Wall")
{
AddReward(-0.05f);
}
}
// punishment for staying at a wall
private void OnCollisionStay(Collision other) {
if (other.gameObject.tag == "Wall")
{
AddReward(-0.05f);
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: a23c7d66d3ff94847a946cf7b30ca1b7 guid: f5cda3de98f45464999f00bdd795f2a0
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@@ -1,44 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CarControl : MonoBehaviour
{
public float motorTorque = 2000;
public float maxSpeed = 20;
public float steeringRange = 30;
//public float steeringRangeAtMaxSpeed = 10;
WheelControl[] wheels;
Rigidbody rigidBody;
// Start is called before the first frame update
void Start()
{
rigidBody = GetComponent<Rigidbody>();
// Find all child GameObjects that have the WheelControl script attached
wheels = GetComponentsInChildren<WheelControl>();
}
// Update is called once per frame
void FixedUpdate()
{
float vInput = Input.GetAxis("Vertical");
float hInput = Input.GetAxis("Horizontal");
foreach (var wheel in wheels)
{
// Apply steering to Wheel colliders that have "Steerable" enabled
if (wheel.steerable)
{
wheel.WheelCollider.steerAngle = hInput * steeringRange;
}
// Apply torque to Wheel colliders that have "Motorized" enabled
if (wheel.motorized)
{
wheel.WheelCollider.motorTorque = vInput * motorTorque;
}
}
}
}

View File

@@ -5,4 +5,20 @@ using UnityEngine;
public class Checkpoint : MonoBehaviour public class Checkpoint : MonoBehaviour
{ {
public bool isCollected = false; public bool isCollected = false;
MeshRenderer meshRenderer;
private void Start() {
meshRenderer = GetComponent<MeshRenderer>();
}
private void Update() {
if (isCollected)
{
meshRenderer.enabled = false;
}
else
{
meshRenderer.enabled = true;
}
}
} }

View File

@@ -1,59 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VehichleControl : MonoBehaviour
{
public InputController InputCtrl;
[Tooltip("Set ref in order of FL, FR, RL, RR")]
public WheelCollider[] WheelColliders;
[Tooltip("Set ref of wheel meshes in order of FL, FR, RL, RR")]
public Transform[] Wheels;
public Transform CenterOfMass;
public int Force;
public int Angle;
public int BrakeForce;
private void Drive()
{
WheelColliders[0].motorTorque = WheelColliders[1].motorTorque = InputCtrl.Vertical * Force;
}
private void Steer()
{
WheelColliders[0].steerAngle = WheelColliders[1].steerAngle = InputCtrl.Horizontal * Angle;
}
private void Brake()
{
WheelColliders[0].brakeTorque = WheelColliders[1].brakeTorque = InputCtrl.Brake * BrakeForce;
}
private void UpdateWheelMovements()
{
for (var i = 0; i < Wheels.Length; i++)
{
Vector3 pos;
Quaternion rot;
WheelColliders[i].GetWorldPose(out pos, out rot);
Wheels[i].transform.position = pos;
Wheels[i].transform.rotation = rot;
}
}
private void FixedUpdate()
{
Steer();
Drive();
Brake();
UpdateWheelMovements();
}
private void Start()
{
GetComponent<Rigidbody>().centerOfMass = CenterOfMass.localPosition;
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 8c9672ffa7e21bf41b27f35da94be659
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: