From 04247b313c0dbfb43ed42a17956853accb2955f5 Mon Sep 17 00:00:00 2001 From: Benjamin Comeau Date: Sat, 7 Nov 2015 16:11:05 -0500 Subject: [PATCH 1/2] Le monstre va suivre le player --- Assets/Scenes/BenScene.unity.meta | 8 ++++++++ Assets/Scripts/FirstPersonController.cs.meta | 12 ++++++++++++ Assets/Scripts/monsterAI.cs | 10 +++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 Assets/Scenes/BenScene.unity.meta create mode 100644 Assets/Scripts/FirstPersonController.cs.meta diff --git a/Assets/Scenes/BenScene.unity.meta b/Assets/Scenes/BenScene.unity.meta new file mode 100644 index 0000000..0182e7e --- /dev/null +++ b/Assets/Scenes/BenScene.unity.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2c1843c7ef59c4177a8d1c75cf7f8399 +timeCreated: 1446925711 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/FirstPersonController.cs.meta b/Assets/Scripts/FirstPersonController.cs.meta new file mode 100644 index 0000000..bc134db --- /dev/null +++ b/Assets/Scripts/FirstPersonController.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 4bcce75dab8f540b797340354c772d8b +timeCreated: 1446927249 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/monsterAI.cs b/Assets/Scripts/monsterAI.cs index 0b37fed..5d87165 100644 --- a/Assets/Scripts/monsterAI.cs +++ b/Assets/Scripts/monsterAI.cs @@ -9,6 +9,9 @@ public class monsterAI : MonoBehaviour public float rotationDamping; // Lower rotation damping = slower rotation public float moveSpeed; + + public float distance; + // Use this for initialization void Start () { @@ -31,15 +34,16 @@ public class monsterAI : MonoBehaviour // Check is the current distance is deadly for the target bool IsAtDeadlyDistance () { - return (deadlyDistance <= Vector3.Distance (target.position, transform.position)); + return (Vector3.Distance (target.position, transform.position) <= deadlyDistance); } // Look toward target void LookAtTarget () { - //Quaternion rotation = Quaternion.LookRotation (target.rotation - transform.rotation); - //transform.rotation = Quaternion.Slerp (transform.rotation, rotation, Time.deltaTime * rotationDamping); + Vector3 relativePos = target.position - transform.position; + Quaternion rotation = Quaternion.LookRotation (relativePos); + transform.rotation = Quaternion.Slerp (transform.rotation, rotation, Time.deltaTime * rotationDamping); } // Follow player from a certain initial distance at a certain speed. void MoveTowardTarget () From 85e6f24f17284c8e5143a883679aacc7c800fd62 Mon Sep 17 00:00:00 2001 From: Benjamin Comeau Date: Sat, 7 Nov 2015 16:30:46 -0500 Subject: [PATCH 2/2] clean up script AI --- Assets/Scenes/BenScene.unity | 127 +++++++++++++++++++++++--- Assets/Scripts/monsterAI.cs | 1 + ProjectSettings/ProjectSettings.asset | 8 +- 3 files changed, 118 insertions(+), 18 deletions(-) diff --git a/Assets/Scenes/BenScene.unity b/Assets/Scenes/BenScene.unity index 3e2ea93..954a9c1 100644 --- a/Assets/Scenes/BenScene.unity +++ b/Assets/Scenes/BenScene.unity @@ -97,6 +97,7 @@ GameObject: - 136: {fileID: 949023943} - 23: {fileID: 949023942} - 114: {fileID: 949023941} + - 54: {fileID: 949023946} m_Layer: 0 m_Name: Monster m_TagString: Untagged @@ -115,10 +116,11 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 10ca748d7d0094f16b50525c5401d788, type: 3} m_Name: m_EditorClassIdentifier: - player: {fileID: 0} - deadlyDistance: 0 - rotationDamping: 0 - moveSpeed: 0 + player: {fileID: 1900049395} + deadlyDistance: 1 + rotationDamping: 2 + moveSpeed: .5 + distance: 0 --- !u!23 &949023942 MeshRenderer: m_ObjectHideFlags: 0 @@ -170,12 +172,27 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 949023940} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalPosition: {x: 0, y: 1, z: 4.71000004} + m_LocalScale: {x: .200000003, y: .200000003, z: .200000003} m_Children: - {fileID: 1632708745} m_Father: {fileID: 0} - m_RootOrder: 3 + m_RootOrder: 4 +--- !u!54 &949023946 +Rigidbody: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 949023940} + serializedVersion: 2 + m_Mass: 1 + m_Drag: 0 + m_AngularDrag: .0500000007 + m_UseGravity: 1 + m_IsKinematic: 0 + m_Interpolate: 0 + m_Constraints: 12 + m_CollisionDetection: 0 --- !u!1 &1335793729 GameObject: m_ObjectHideFlags: 0 @@ -235,7 +252,93 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 2 + m_RootOrder: 3 +--- !u!1 &1447592087 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 1447592092} + - 33: {fileID: 1447592091} + - 64: {fileID: 1447592090} + - 23: {fileID: 1447592089} + - 65: {fileID: 1447592088} + m_Layer: 0 + m_Name: Sol + m_TagString: Floor + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!65 &1447592088 +BoxCollider: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1447592087} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 1, y: .999999881, z: 6.12323294e-17} + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &1447592089 +MeshRenderer: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1447592087} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_Materials: + - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} + m_SubsetIndices: + m_StaticBatchRoot: {fileID: 0} + m_UseLightProbes: 1 + m_ReflectionProbeUsage: 1 + m_ProbeAnchor: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 1 + m_ImportantGI: 0 + m_AutoUVMaxDistance: .5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingOrder: 0 +--- !u!64 &1447592090 +MeshCollider: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1447592087} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 0 + serializedVersion: 2 + m_Convex: 0 + m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0} +--- !u!33 &1447592091 +MeshFilter: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1447592087} + m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &1447592092 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1447592087} + m_LocalRotation: {x: .707106829, y: 0, z: 0, w: .707106709} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 40, y: 40, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 --- !u!1 &1632708744 GameObject: m_ObjectHideFlags: 0 @@ -390,11 +493,11 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 1741083282} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 1, z: -10} + m_LocalPosition: {x: 0, y: 2, z: -10} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 1 + m_RootOrder: 2 --- !u!1 &1792249522 GameObject: m_ObjectHideFlags: 0 @@ -507,12 +610,12 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 1900049395} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: .545000017, z: -.409999996} + m_LocalPosition: {x: 0, y: 1, z: -.409999996} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 1792249527} m_Father: {fileID: 0} - m_RootOrder: 0 + m_RootOrder: 1 --- !u!82 &1900049397 AudioSource: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/monsterAI.cs b/Assets/Scripts/monsterAI.cs index 5d87165..2020c25 100644 --- a/Assets/Scripts/monsterAI.cs +++ b/Assets/Scripts/monsterAI.cs @@ -45,6 +45,7 @@ public class monsterAI : MonoBehaviour transform.rotation = Quaternion.Slerp (transform.rotation, rotation, Time.deltaTime * rotationDamping); } + // Follow player from a certain initial distance at a certain speed. void MoveTowardTarget () { diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 83cca07..8d657e2 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -163,10 +163,8 @@ PlayerSettings: m_BuildTargetIcons: - m_BuildTarget: m_Icons: - - serializedVersion: 2 - m_Icon: {fileID: 0} - m_Width: 128 - m_Height: 128 + - m_Icon: {fileID: 0} + m_Size: 0 m_BuildTargetBatching: [] m_BuildTargetGraphicsAPIs: [] webPlayerTemplate: APPLICATION:Default @@ -260,8 +258,6 @@ PlayerSettings: ps4pnGameCustomData: 1 playerPrefsSupport: 0 ps4ReprojectionSupport: 0 - ps4UseAudio3dBackend: 0 - ps4Audio3dVirtualSpeakerCount: 14 ps4attribUserManagement: 0 ps4attribMoveSupport: 0 ps4attrib3DSupport: 0