added ears to the player
This commit is contained in:
Banane_Rotative
2025-03-06 14:30:37 +01:00
parent 2bc676efed
commit 736f1ed646
7 changed files with 368 additions and 22 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 73ee6726d5b62ab45b19908789aaac14
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
fileFormatVersion: 2
guid: cb6c4215b8cd7b64cbee2efc72969545
AudioImporter:
externalObjects: {}
serializedVersion: 8
defaultSettings:
serializedVersion: 2
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
preloadAudioData: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -225,11 +225,12 @@ Transform:
m_GameObject: {fileID: 99782791}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0.96, z: 0}
m_LocalPosition: {x: 0, y: 0.96, z: -5.86}
m_LocalScale: {x: 1, y: 0.9, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1561010223}
- {fileID: 493760350}
- {fileID: 330585546}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -245,6 +246,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 477e133ae7cec0f44b29e6fb665c5e00, type: 3}
m_Name:
m_EditorClassIdentifier:
ears: {fileID: 493760352}
speed: 15
sensitivity: 70
maxSpeed: 10
@@ -257,7 +259,7 @@ Rigidbody:
m_GameObject: {fileID: 99782791}
serializedVersion: 4
m_Mass: 1
m_Drag: 0
m_Drag: 2
m_AngularDrag: 0.05
m_CenterOfMass: {x: 0, y: 0, z: 0}
m_InertiaTensor: {x: 1, y: 1, z: 1}
@@ -394,7 +396,6 @@ GameObject:
m_Component:
- component: {fileID: 330585546}
- component: {fileID: 330585545}
- component: {fileID: 330585544}
- component: {fileID: 330585547}
m_Layer: 0
m_Name: Debug Camera
@@ -403,14 +404,6 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &330585544
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 330585543}
m_Enabled: 1
--- !u!20 &330585545
Camera:
m_ObjectHideFlags: 0
@@ -642,6 +635,91 @@ MonoBehaviour:
m_LightCookieSize: {x: 1, y: 1}
m_LightCookieOffset: {x: 0, y: 0}
m_SoftShadowQuality: 1
--- !u!1 &493760349
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 493760350}
- component: {fileID: 493760351}
- component: {fileID: 493760352}
m_Layer: 0
m_Name: Ears
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &493760350
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 493760349}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0.453, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 990919147}
m_Father: {fileID: 99782795}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!81 &493760351
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 493760349}
m_Enabled: 1
--- !u!114 &493760352
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 493760349}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5a895e8a798ee0b4a9a5ea33d6b07f4b, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &990919146
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 990919147}
m_Layer: 0
m_Name: rotation center
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &990919147
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 990919146}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: -0.14, z: -0.3}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 493760350}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1561010222
GameObject:
m_ObjectHideFlags: 0
@@ -833,9 +911,216 @@ Transform:
m_LocalPosition: {x: -0.65822375, y: 0.391, z: 1.873}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Children:
- {fileID: 1883178834}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1883178833
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1883178834}
- component: {fileID: 1883178838}
- component: {fileID: 1883178837}
- component: {fileID: 1883178836}
- component: {fileID: 1883178835}
m_Layer: 0
m_Name: Soundbox
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1883178834
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1883178833}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0.244, y: 0.588, z: -0.09}
m_LocalScale: {x: 0.2, y: 0.2, z: 0.2}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1697224671}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!82 &1883178835
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1883178833}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: cb6c4215b8cd7b64cbee2efc72969545, type: 3}
m_Resource: {fileID: 8300000, guid: cb6c4215b8cd7b64cbee2efc72969545, type: 3}
m_PlayOnAwake: 1
m_Volume: 1
m_Pitch: 1
Loop: 1
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 500
Pan2D: 0
rolloffMode: 0
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
panLevelCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
spreadCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
reverbZoneMixCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!65 &1883178836
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1883178833}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &1883178837
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1883178833}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &1883178838
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1883178833}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1660057539 &9223372036854775807
SceneRoots:
m_ObjectHideFlags: 0

View File

@@ -0,0 +1,9 @@
using UnityEngine;
public class EarsController : MonoBehaviour
{
public void RotateHead(Vector3 rotation) {
transform.localEulerAngles = new Vector3(rotation.x, 0, rotation.z);
// More advanced rotation would require another rotation center
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5a895e8a798ee0b4a9a5ea33d6b07f4b

View File

@@ -3,22 +3,30 @@ using UnityEngine;
// Handles everything related to player movement
public class PlayerController : MonoBehaviour
{
private PlayerControlsMap playerControls;
private Rigidbody rb;
[SerializeField] private EarsController ears = null;
[SerializeField] private float speed = 15;
[SerializeField] private float sensitivity = 50;
[SerializeField] private float maxSpeed = 10;
private PlayerControlsMap playerControls;
private Rigidbody rb;
private Vector3 currentRotation = Vector3.zero;
// Awake is always called before Start. Often used to initialize variables
void Awake()
{
playerControls = new PlayerControlsMap();
rb = GetComponent<Rigidbody>();
if (ears == null) { // If not assigned within editor
Debug.LogError("ears attribute of " + name + " should be assigned within editor. (ears object should be a child of " + name + ")");
}
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
// Often used to initialize variables which are dependent to other scripts/components
// Often used to initialize variables which are dependent to other scripts/components variables
void Start()
{
@@ -37,20 +45,31 @@ public class PlayerController : MonoBehaviour
// Update is called once per frame
void Update()
{
// Update player direction. Very basic.
RotatePlayer();
MovePlayer();
}
void RotatePlayer() {
// Update player direction. Very basic
// First, rotate player on y axis
Vector2 lookInput = playerControls.Player.Look.ReadValue<Vector2>();
lookInput *= sensitivity * Time.deltaTime;
Quaternion currentRotation = transform.rotation;
currentRotation *= Quaternion.AngleAxis(lookInput.x, Vector3.up);
transform.rotation = currentRotation;
// We ignore vertical rotation as it would have no impact on the game
currentRotation += new Vector3(Mathf.Clamp(-lookInput.y, -90, 90), lookInput.x, 0);
transform.localEulerAngles = new Vector3(0, currentRotation.y, 0);
// Then, rotate player's ears on both x and z axes (only available with certain controllers such as AR/VR)
ears.RotateHead(new Vector3(currentRotation.x, 0, currentRotation.z));
}
void MovePlayer() {
// Update player acceleration, using a force
Vector2 mvtInput = playerControls.Player.Move.ReadValue<Vector2>();
mvtInput *= speed * Time.deltaTime;
rb.AddForce(currentRotation * new Vector3(mvtInput.x, 0, mvtInput.y), ForceMode.VelocityChange);
rb.AddForce(transform.rotation * new Vector3(mvtInput.x, 0, mvtInput.y), ForceMode.VelocityChange);
// Limit max speed. Warning: both maxSpeed and rigidbody linear damping affect max speed
// Limit max speed.
// maxSpeed affects only max speed, while rigidbody's linear damping affects both max speed and deceleration
if (rb.linearVelocity.magnitude > maxSpeed) {
rb.linearVelocity = rb.linearVelocity.normalized * maxSpeed;
}