Make Shello rotate towards the player before jumping (this still needs work)

Convert all scripts to used tagged Player.
Try to keep Shello on the ground while walking (not sure if this works yet).
Fix transition from excitement to walking to happen immediately.
This commit is contained in:
gunnbr committed 2021-01-17 10:22:11 -08:00
1 parent 3f9ac3eb81
commit 12145753f0
11 files changed
+1664 -841

No files matched your search

@@ -149,19 +149,19 @@ AnimatorController:
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 0} m_Controller: {fileID: 9100000}
- m_Name: isWalking - m_Name: isWalking
m_Type: 4 m_Type: 4
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 0} m_Controller: {fileID: 9100000}
- m_Name: isSwimming - m_Name: isSwimming
m_Type: 4 m_Type: 4
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 0} m_Controller: {fileID: 9100000}
m_AnimatorLayers: m_AnimatorLayers:
- serializedVersion: 5 - serializedVersion: 5
m_Name: Base Layer m_Name: Base Layer
@@ -195,7 +195,7 @@ AnimatorStateTransition:
m_TransitionDuration: 0.25 m_TransitionDuration: 0.25
m_TransitionOffset: 0 m_TransitionOffset: 0
m_ExitTime: 0.86607146 m_ExitTime: 0.86607146
m_HasExitTime: 1 m_HasExitTime: 0
m_HasFixedDuration: 1 m_HasFixedDuration: 1
m_InterruptionSource: 0 m_InterruptionSource: 0
m_OrderedInterruption: 1 m_OrderedInterruption: 1
+7 -1
View File
@@ -5,19 +5,25 @@ using UnityEngine.AI;
public class FollowerController : MonoBehaviour public class FollowerController : MonoBehaviour
{ {
public Transform target;
public float wakeDistance; public float wakeDistance;
private NavMeshAgent agent; private NavMeshAgent agent;
private AudioSource audioSource; private AudioSource audioSource;
private Animator[] anims; private Animator[] anims;
private bool isFollowing = false; private bool isFollowing = false;
private Transform target;
void Start() void Start()
{ {
agent = GetComponent<NavMeshAgent>(); agent = GetComponent<NavMeshAgent>();
anims = GetComponentsInChildren<Animator>(); anims = GetComponentsInChildren<Animator>();
audioSource = GetComponent<AudioSource>(); audioSource = GetComponent<AudioSource>();
var players = GameObject.FindGameObjectsWithTag("Player");
if (players?.Length > 0)
{
target = players[0].transform;
}
} }
// Update is called once per frame // Update is called once per frame
+6 -1
View File
@@ -6,13 +6,18 @@ public class OwlController : MonoBehaviour
{ {
Animator anim; Animator anim;
public Transform player; Transform player;
public float startle_distance; public float startle_distance;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
anim = GetComponent<Animator>(); anim = GetComponent<Animator>();
var players = GameObject.FindGameObjectsWithTag("Player");
if (players?.Length > 0)
{
player = players[0].transform;
}
} }
// Update is called once per frame // Update is called once per frame
@@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: c814d2df27a2eb14d9f6198b08046609
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: c1a880a7693de5647aa7ad099e908b3a
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 8f68dd1e5500b174190f64e4013d4916
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large. Load diff
+55 -2
View File
@@ -4,8 +4,13 @@ using UnityEngine;
public class ShelloController : MonoBehaviour public class ShelloController : MonoBehaviour
{ {
public LayerMask terainMask;
public float notice_distance; public float notice_distance;
// Angular speed in radians per sec.
public float rotationSpeed = 1.0f;
public float excitedDirection = 5;
Transform player; Transform player;
Animator anim; Animator anim;
bool isAwake = false; bool isAwake = false;
@@ -37,17 +42,65 @@ public class ShelloController : MonoBehaviour
float dist = Vector3.Distance(player.position, transform.position); float dist = Vector3.Distance(player.position, transform.position);
var isExcited = dist < notice_distance; var isExcited = dist < notice_distance;
if (!isExcited)
{
return;
}
// Determine which direction to rotate towards
Vector3 targetDirection = player.position - transform.position;
// The step size is equal to speed times frame time.
float singleStep = rotationSpeed * Time.deltaTime;
// Rotate the forward vector towards the target direction by one step
Vector3 newDirection = Vector3.RotateTowards(transform.forward, targetDirection, singleStep, 0.0f);
// Draw a ray pointing at our target in
Debug.DrawRay(transform.position, newDirection, Color.red);
var rotateDiff = transform.forward.y - targetDirection.y;
// Calculate a rotation a step closer to the target and applies rotation to this object
transform.rotation = Quaternion.LookRotation(newDirection);
if (Mathf.Abs(rotateDiff) < excitedDirection)
{
anim.SetBool("isExcited", isExcited); anim.SetBool("isExcited", isExcited);
if (isExcited) if (isExcited)
{ {
awokenFrames++; awokenFrames++;
if (awokenFrames > 120) if (awokenFrames > 60)
{ {
anim.SetBool("isExcited", false);
anim.SetBool("isWalking", true); anim.SetBool("isWalking", true);
anim.SetBool("isExcited", false);
isAwake = true; isAwake = true;
} }
} }
}
else
{
Debug.Log($"Rotation diff: {rotateDiff}");
}
}
void FixedUpdate()
{
Align();
}
private void Align()
{
RaycastHit hit;
var theRay = -transform.up;
if (Physics.Raycast(new Vector3(transform.position.x, transform.position.y, transform.position.z),
theRay, out hit, 20, terainMask))
{
Quaternion targetRotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.parent.rotation;
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.deltaTime / 0.15f);
transform.position = new Vector3(transform.position.x, transform.position.y - hit.distance, transform.position.z);
}
} }
} }
+1 -1
View File
@@ -143,7 +143,7 @@
"depth": 1, "depth": 1,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
"com.unity.subsystemregistration": "1.0.5" "com.unity.subsystemregistration": "1.0.6"
}, },
"url": "https://packages.unity.com" "url": "https://packages.unity.com"
}, },
+2 -1
View File
@@ -222,4 +222,5 @@ QualitySettings:
resolutionScalingFixedDPIFactor: 1 resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0} customRenderPipeline: {fileID: 0}
excludedTargetPlatforms: [] excludedTargetPlatforms: []
m_PerPlatformDefaultQuality: {} m_PerPlatformDefaultQuality:
Standalone: 0
+167
View File
@@ -0,0 +1,167 @@
{
"templatePinStates": [],
"dependencyTypeInfos": [
{
"userAdded": false,
"type": "UnityEngine.AnimationClip",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEditor.Animations.AnimatorController",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.AnimatorOverrideController",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEditor.Audio.AudioMixerController",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.ComputeShader",
"ignore": true,
"defaultInstantiationMode": 1,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.Cubemap",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.GameObject",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEditor.LightingDataAsset",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": false
},
{
"userAdded": false,
"type": "UnityEngine.LightingSettings",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.Material",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEditor.MonoScript",
"ignore": true,
"defaultInstantiationMode": 1,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.PhysicMaterial",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.PhysicsMaterial2D",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.Rendering.PostProcessing.PostProcessProfile",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.Rendering.PostProcessing.PostProcessResources",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.Rendering.VolumeProfile",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEditor.SceneAsset",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": false
},
{
"userAdded": false,
"type": "UnityEngine.Shader",
"ignore": true,
"defaultInstantiationMode": 1,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.ShaderVariantCollection",
"ignore": true,
"defaultInstantiationMode": 1,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.Texture",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.Texture2D",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
},
{
"userAdded": false,
"type": "UnityEngine.Timeline.TimelineAsset",
"ignore": false,
"defaultInstantiationMode": 0,
"supportsModification": true
}
],
"defaultDependencyTypeInfo": {
"userAdded": false,
"type": "<default_scene_template_dependencies>",
"ignore": false,
"defaultInstantiationMode": 1,
"supportsModification": true
},
"newSceneOverride": 0
}