Steam lobby implemented

This commit is contained in:
Madhav Kapa
2023-06-01 08:03:48 -07:00
parent c7647c8097
commit 49efee80e2
95 changed files with 10258 additions and 6167 deletions

View File

@ -1,152 +1,131 @@
using System.Collections;
using System.Collections.Generic;
using UnityEditor.Rendering;
using UnityEngine;
using UnityEngine.Events;
public class SkinlessMonsterAnimator : MonoBehaviour
{
[SerializeField]
private Animator animator;
private float speed = 0f;
[SerializeField] private Animator animator;
[SerializeField]
[Tooltip("This is the object with the skin dissolve material")]
[SerializeField] [Tooltip("This is the object with the skin dissolve material")]
private GameObject modelObject;
[SerializeField]
private List<GameObject> objectsThatFallOnDeath= new List<GameObject>();
[SerializeField] private List<GameObject> objectsThatFallOnDeath = new();
[SerializeField] private float deathSpeed = 5f;
[SerializeField] private float fastDeathduration = 1f;
[SerializeField] private float deathDuration = 5f;
private float curDeathSpeed = 5f;
private Material dissolveMaterial;
private bool isAlive = true;
[SerializeField]
private float deathSpeed = 5f;
private float curDeathSpeed = 5f;
private bool isRunning = false;
public bool IsRunning { get { return isRunning; } }
[SerializeField]
private float fastDeathduration = 1f;
[SerializeField]
private float deathDuration = 5f;
private float speed;
public bool IsRunning { get; private set; }
// Start is called before the first frame update
void Start()
private void Start()
{
dissolveMaterial = modelObject.GetComponent<SkinnedMeshRenderer>().materials[0];
curDeathSpeed = deathSpeed;
}
// Update is called once per frame
void Update()
private void Update()
{
if (isAlive)
{
animator.SetFloat("Speed", speed);
}
else
{
float quantity = dissolveMaterial.GetFloat("_DissolveQuantity");
quantity = Mathf.Lerp(quantity, -2, Time.deltaTime *curDeathSpeed);
var quantity = dissolveMaterial.GetFloat("_DissolveQuantity");
quantity = Mathf.Lerp(quantity, -2, Time.deltaTime * curDeathSpeed);
dissolveMaterial.SetFloat("_DissolveQuantity", quantity);
}
}
public void StartMoving()
{
if (isAlive)
{
isRunning = true;
IsRunning = true;
speed = 1;
}
}
public void StopMoving()
{
if (isAlive)
{
speed = 0;
isRunning = false;
IsRunning = false;
}
}
public void Attack()
{
if (isAlive)
{
animator.SetTrigger("Attack");
}
if (isAlive) animator.SetTrigger("Attack");
}
/// <summary>
/// 0,1,2,3
/// 0,1,2,3
/// </summary>
/// <param name="attackType"></param>
public void SetAttackType(int attackType)
{
animator.SetInteger("AttackIndex", attackType);
}
public void InLight()
{
if(isAlive)
animator.SetBool("InLight", true);
if (isAlive)
animator.SetBool("InLight", true);
}
public void NotInLight()
{
if(isAlive)
animator.SetBool("InLight", false);
if (isAlive)
animator.SetBool("InLight", false);
}
public void AttackScream()
{
if(isAlive)
animator.SetTrigger("AttackScream");
if (isAlive)
animator.SetTrigger("AttackScream");
}
public void Kill(bool fast = false)
{
//animator.speed = 0;
InLight();
isAlive = false;
foreach(GameObject obj in this.objectsThatFallOnDeath)
foreach (var obj in objectsThatFallOnDeath)
{
obj.AddComponent<Rigidbody>();
if (obj.GetComponent<Collider>() != null)
{
obj.GetComponent<Collider>().enabled = false;
}
if (obj.GetComponent<Collider>() != null) obj.GetComponent<Collider>().enabled = false;
}
float dur = this.deathDuration;
var dur = deathDuration;
if (fast)
{
dur = this.fastDeathduration;
curDeathSpeed = deathSpeed * (this.deathDuration / this.fastDeathduration);
dur = fastDeathduration;
curDeathSpeed = deathSpeed * (deathDuration / fastDeathduration);
}
StartCoroutine(destroyAfterSeconds(dur));
}
private IEnumerator destroyAfterSeconds(float duration)
{
yield return new WaitForSeconds(duration);
Destroy(this.gameObject);
Destroy(gameObject);
}
}
}

View File

@ -1,321 +1,79 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class SkinlessMonsterComponent : MonoBehaviour
{
[SerializeField]
private NavMeshAgent agent;
[SerializeField]
private SkinlessMonsterAnimator animator;
private bool inDamageRange = false;
private bool inDamageMargin = false;
private bool atTarget = false;
[SerializeField]
private float atTargetDistance = 2;
private TargetInformation target;
[SerializeField] private NavMeshAgent agent;
[SerializeField]
private float health = 2f;
[SerializeField] private SkinlessMonsterAnimator animator;
[SerializeField] private float atTargetDistance = 2;
[SerializeField] private float health = 2f;
[SerializeField] [Tooltip("This is the angle of visibility the enemy has")]
private float visibilityConeLimit = 90f;
[SerializeField] private float bulletSoundRange = 15f;
[SerializeField] private float newTargetCooldown = 5f;
//private bool prePauseStoppedState = false;
[SerializeField] private BoxCollider leftHandDamage;
[SerializeField] private BoxCollider rightHandDamage;
private bool atTarget;
private float distanceToPlayer;
private FlareRegister flareRegister;
private bool inDamageMargin;
private bool inDamageRange;
private bool isAlive = true;
private InGameManager manager;
private Vector3 oppositeVector;
private PlayerComponent player;
private float distanceToPlayer;
private FlareRegister flareRegister;
[SerializeField]
[Tooltip("This is the angle of visibility the enemy has")]
private float visibilityConeLimit = 90f;
[SerializeField]
private float bulletSoundRange = 15f;
private TargetInformation target;
private GameObject targetObject;
[SerializeField]
private float newTargetCooldown = 5f;
private float timeSinceTarget = 0f;
private InGameManager manager;
//private bool prePauseStoppedState = false;
[SerializeField]
private BoxCollider leftHandDamage;
[SerializeField]
private BoxCollider rightHandDamage;
private float timeSinceTarget;
private void Awake()
{
//Find active player rn.
PlayerComponent[] players = GameObject.FindObjectsOfType<PlayerComponent>();
foreach (PlayerComponent p in players)
{
var players = FindObjectsOfType<PlayerComponent>();
foreach (var p in players)
if (p.isActiveAndEnabled)
{
player = p;
}
}
manager = GameObject.FindObjectOfType<InGameManager>();
manager = FindObjectOfType<InGameManager>();
}
private void Start()
{
flareRegister = GameObject.FindObjectOfType<FlareRegister>();
flareRegister = FindObjectOfType<FlareRegister>();
if (targetObject == null)
targetObject = new GameObject();
targetObject.name = "Enemy Target";
if(player == null)
{
player = GameObject.FindObjectOfType<PlayerComponent>();
}
}
void HandleTargetOperations()
{
//Update booleans for movement
float distToTarget = Vector3.Distance(target.target.transform.position, agent.transform.position);
atTarget = atTargetDistance >= distToTarget;
if (target.hasDamageRange)
{
inDamageRange = target.damageRange <= distToTarget;
inDamageMargin = target.damageMargin + target.damageRange <= distToTarget;
}
else
{
inDamageRange = false;
inDamageMargin = false;
}
//Perform actions.
if (target.runTowards)
{
if (inDamageRange)
{
//Damage is being dealt
animator.InLight();
//Deal Damage
health -= Time.deltaTime;
if (health < 0 && this.isAlive)
{
this.Kill();
}
}
else if (inDamageMargin)
{
//Effective stop
agent.SetDestination(transform.position);
animator.StopMoving();
}
else
{
if (atTarget)
{
//Effective stop
agent.SetDestination(transform.position);
animator.StopMoving();
if (target.isHostile)
{
animator.Attack();
animator.SetAttackType(Random.Range(0, 0));
}
}
else
{
agent.SetDestination(target.target.transform.position);
animator.StartMoving();
animator.NotInLight();
}
}
}
else
{
//Run away logic
if (atTarget || distToTarget < 3)
{
animator.StopMoving();
}
else
{
Ray r = new Ray();
r.origin = transform.position;
r.direction = oppositeVector;
RaycastHit hit;
if (Physics.Raycast(r, out hit))
{
animator.StartMoving();
agent.SetDestination(hit.point);
}
else
{
agent.SetDestination(transform.position + oppositeVector * 100);
agent.isStopped = false;
}
}
}
if (atTarget&&target.isHostile)
{
SlowLookAt(target.target.transform.position-transform.position);
}
}
void SlowLookAt(Vector3 targetVector,float animatedRotationSpeed=1f)
{
Vector3 relativePos = targetVector;
Quaternion toRotation = Quaternion.LookRotation(relativePos);
transform.rotation = Quaternion.Lerp(transform.rotation, toRotation, animatedRotationSpeed * Time.deltaTime);
}
void CheckForAOERanges()
{
foreach(BulletComponent bullet in flareRegister.bullets)
{
float dist = Vector3.Distance(bullet.transform.position, transform.position);
if (dist <= bullet.DamageRange)
{
this.health = 0;
this.Kill(true);
}
}
foreach(FlareBeacon beacon in flareRegister.beacons)
{
float dist = Vector3.Distance(beacon.transform.position, transform.position);
if (dist <= beacon.Range)
{
this.health = 0f;
}
}
if (this.health <= 0)
{
this.Kill();
}
}
public bool isPlayerVisible(bool withAngle)
{
Ray r = new Ray();
r.origin = transform.position;
r.direction = player.transform.position - transform.position;
Vector3 toPosition = (player.transform.position - transform.position).normalized;
float angleToPosition = Vector3.Angle(transform.forward, toPosition);
RaycastHit hit;
if(Physics.Raycast(r, out hit))
{
GameObject hitObject = hit.transform.gameObject;
if (hitObject.GetComponent<PlayerComponent>() != null)
{
//hit player
return angleToPosition <= this.visibilityConeLimit||!withAngle;
}else if (hitObject.GetComponentInParent<PlayerComponent>() != null)
{
//also hit player
return angleToPosition <= this.visibilityConeLimit||!withAngle;
}
}
return false;
}
void SetLiveTargeting()
{
if (!isAlive)
{
//this.targetObject.transform.position = transform.position;
this.Stop();
}
distanceToPlayer = Vector3.Distance(this.transform.position, player.transform.position);
//print("Dist Comparison "+distanceToPlayer.ToString()+" Noise:"+player.NoiseManager.NoiseDistance);
bool isPlayerVisible = this.isPlayerVisible(true);
//check if player is heard or player line of sight
if (distanceToPlayer <= player.NoiseManager.NoiseDistance||isPlayerVisible)
{
//check that nothing in between
if (this.isPlayerVisible(false))
{
this.Target(player.gameObject, true);
}
}
else
{
if (this.timeSinceTarget < this.newTargetCooldown)
{
//no further targeting
//Stop();
return;
}
BulletComponent closestBullet = null;
float closestDistance = Mathf.Infinity;
foreach(BulletComponent bullet in this.flareRegister.bullets)
{
float bDist = Vector3.Distance(bullet.transform.position, transform.position);
if (closestBullet==null||(bDist< bulletSoundRange&&bDist<closestDistance))
{
closestBullet = bullet;
closestDistance = bDist;
}
}
if (closestBullet != null&&closestBullet.DamageRange==0)
{
targetObject.transform.position= closestBullet.transform.position;
this.Target(targetObject,false);
}
else
{
targetObject.transform.position = transform.position;
this.Target(targetObject,false);
this.Stop();
}
}
if (player == null) player = FindObjectOfType<PlayerComponent>();
}
private void Update()
{
if (!player.IsAlive)
{
Stop();
}
if (target != null)
{
HandleTargetOperations();
}
if (!player.IsAlive) Stop();
if (target != null) HandleTargetOperations();
CheckForAOERanges();
if(isAlive&&player.IsAlive)
if (isAlive && player.IsAlive)
SetLiveTargeting();
timeSinceTarget += Time.deltaTime;
if (this.isAlive)
if (isAlive)
{
leftHandDamage.enabled = true;
rightHandDamage.enabled = true;
@ -325,7 +83,7 @@ public class SkinlessMonsterComponent : MonoBehaviour
leftHandDamage.enabled = false;
rightHandDamage.enabled = false;
}
/*
AI Behavior:
@ -345,6 +103,197 @@ public class SkinlessMonsterComponent : MonoBehaviour
- stop() and wait for player to leave AOE (enforced by navigation).
*/
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.GetComponent<BulletComponent>() != null)
health -= other.gameObject.GetComponent<BulletComponent>().DamageMagnitude;
}
private void HandleTargetOperations()
{
//Update booleans for movement
var distToTarget = Vector3.Distance(target.target.transform.position, agent.transform.position);
atTarget = atTargetDistance >= distToTarget;
if (target.hasDamageRange)
{
inDamageRange = target.damageRange <= distToTarget;
inDamageMargin = target.damageMargin + target.damageRange <= distToTarget;
}
else
{
inDamageRange = false;
inDamageMargin = false;
}
//Perform actions.
if (target.runTowards)
{
if (inDamageRange)
{
//Damage is being dealt
animator.InLight();
//Deal Damage
health -= Time.deltaTime;
if (health < 0 && isAlive) Kill();
}
else if (inDamageMargin)
{
//Effective stop
agent.SetDestination(transform.position);
animator.StopMoving();
}
else
{
if (atTarget)
{
//Effective stop
agent.SetDestination(transform.position);
animator.StopMoving();
if (target.isHostile)
{
animator.Attack();
animator.SetAttackType(Random.Range(0, 0));
}
}
else
{
agent.SetDestination(target.target.transform.position);
animator.StartMoving();
animator.NotInLight();
}
}
}
else
{
//Run away logic
if (atTarget || distToTarget < 3)
{
animator.StopMoving();
}
else
{
var r = new Ray();
r.origin = transform.position;
r.direction = oppositeVector;
RaycastHit hit;
if (Physics.Raycast(r, out hit))
{
animator.StartMoving();
agent.SetDestination(hit.point);
}
else
{
agent.SetDestination(transform.position + oppositeVector * 100);
agent.isStopped = false;
}
}
}
if (atTarget && target.isHostile) SlowLookAt(target.target.transform.position - transform.position);
}
private void SlowLookAt(Vector3 targetVector, float animatedRotationSpeed = 1f)
{
var relativePos = targetVector;
var toRotation = Quaternion.LookRotation(relativePos);
transform.rotation = Quaternion.Lerp(transform.rotation, toRotation, animatedRotationSpeed * Time.deltaTime);
}
private void CheckForAOERanges()
{
foreach (var bullet in flareRegister.bullets)
{
var dist = Vector3.Distance(bullet.transform.position, transform.position);
if (dist <= bullet.DamageRange)
{
health = 0;
Kill(true);
}
}
foreach (var beacon in flareRegister.beacons)
{
var dist = Vector3.Distance(beacon.transform.position, transform.position);
if (dist <= beacon.Range) health = 0f;
}
if (health <= 0) Kill();
}
public bool isPlayerVisible(bool withAngle)
{
var r = new Ray();
r.origin = transform.position;
r.direction = player.transform.position - transform.position;
var toPosition = (player.transform.position - transform.position).normalized;
var angleToPosition = Vector3.Angle(transform.forward, toPosition);
RaycastHit hit;
if (Physics.Raycast(r, out hit))
{
var hitObject = hit.transform.gameObject;
if (hitObject.GetComponent<PlayerComponent>() != null)
//hit player
return angleToPosition <= visibilityConeLimit || !withAngle;
if (hitObject.GetComponentInParent<PlayerComponent>() != null)
//also hit player
return angleToPosition <= visibilityConeLimit || !withAngle;
}
return false;
}
private void SetLiveTargeting()
{
if (!isAlive)
//this.targetObject.transform.position = transform.position;
Stop();
distanceToPlayer = Vector3.Distance(transform.position, player.transform.position);
//print("Dist Comparison "+distanceToPlayer.ToString()+" Noise:"+player.NoiseManager.NoiseDistance);
var isPlayerVisible = this.isPlayerVisible(true);
//check if player is heard or player line of sight
if (distanceToPlayer <= player.NoiseManager.NoiseDistance || isPlayerVisible)
{
//check that nothing in between
if (this.isPlayerVisible(false)) Target(player.gameObject, true);
}
else
{
if (timeSinceTarget < newTargetCooldown)
//no further targeting
//Stop();
return;
BulletComponent closestBullet = null;
var closestDistance = Mathf.Infinity;
foreach (var bullet in flareRegister.bullets)
{
var bDist = Vector3.Distance(bullet.transform.position, transform.position);
if (closestBullet == null || (bDist < bulletSoundRange && bDist < closestDistance))
{
closestBullet = bullet;
closestDistance = bDist;
}
}
if (closestBullet != null && closestBullet.DamageRange == 0)
{
targetObject.transform.position = closestBullet.transform.position;
Target(targetObject);
}
else
{
targetObject.transform.position = transform.position;
Target(targetObject);
Stop();
}
}
}
/*
STANDARD BEHAVIOR:
- OnSeeing/Hearing Player:
@ -360,9 +309,9 @@ public class SkinlessMonsterComponent : MonoBehaviour
*/
//Runs towards target. If its meant to be hostile, it will melee attack once in range.
public void Target(GameObject obj,bool hostile=false)
public void Target(GameObject obj, bool hostile = false)
{
if(target == null || target.target!= obj)
if (target == null || target.target != obj)
{
//target = new TargetInformation(obj,hostile,false,runTowards:true);
target = new TargetInformation();
@ -371,13 +320,13 @@ public class SkinlessMonsterComponent : MonoBehaviour
target.hasDamageRange = false;
target.runTowards = true;
timeSinceTarget = 0;
}
}
//Runs towards flare such that it stops randomly within margin before range.
public void TargetFlare(GameObject obj,float range,float margin)
public void TargetFlare(GameObject obj, float range, float margin)
{
if(target == null || target.target != obj)
if (target == null || target.target != obj)
{
//target = new TargetInformation(obj, false, true, range, margin,runTowards:true);
target = new TargetInformation();
@ -390,15 +339,17 @@ public class SkinlessMonsterComponent : MonoBehaviour
timeSinceTarget = 0;
}
}
/// <summary>
/// Runs away from object. A minimum range is specified where it no longer takes damage, and a minimum margin is
/// speicifed where it can stop running.
/// Runs away from object. A minimum range is specified where it no longer takes damage, and a minimum margin is
/// speicifed where it can stop running.
/// </summary>
/// <param name="obj"></param>
/// <param name="minRange"></param>
/// <param name="minMargin"></param>
public void RunAwayFrom(GameObject obj,float minRange,float minMargin) {
if(target== null ||target.target != obj)
public void RunAwayFrom(GameObject obj, float minRange, float minMargin)
{
if (target == null || target.target != obj)
{
//target = new TargetInformation(obj, false, true, minRange, minMargin, false);
target = new TargetInformation();
@ -416,44 +367,30 @@ public class SkinlessMonsterComponent : MonoBehaviour
public void Stop()
{
target = new TargetInformation();
target.target = this.gameObject;
target.target = gameObject;
target.isHostile = false;
target.hasDamageRange = false;
target.runTowards = true;
}
public void Kill(bool fast=false)
public void Kill(bool fast = false)
{
if (this.isAlive)
if (isAlive)
{
this.animator.Kill(fast);
this.isAlive = false;
animator.Kill(fast);
isAlive = false;
agent.isStopped = true;
}
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.GetComponent<BulletComponent>() != null)
{
this.health -= other.gameObject.GetComponent<BulletComponent>().DamageMagnitude;
}
}
}
class TargetInformation
{
public GameObject target;
public bool isHostile;
public bool hasDamageRange;
public float damageRange;
internal class TargetInformation
{
public float damageMargin;
public float damageRange;
public bool hasDamageRange;
public bool isHostile;
public bool runTowards;
public GameObject target;
}

View File

@ -1,38 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestSkinnlessMonster : MonoBehaviour
{
[SerializeField]
private SkinlessMonsterComponent monster;
[SerializeField]
private Camera cam;
[SerializeField] private SkinlessMonsterComponent monster;
[SerializeField] private Camera cam;
// Start is called before the first frame update
void Start()
private void Start()
{
}
// Update is called once per frame
void Update()
private void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
monster.Target(cam.gameObject, true);
}
if (Input.GetKeyDown(KeyCode.Alpha2))
{
monster.TargetFlare(cam.gameObject, 1, 1);
}
if (Input.GetKeyDown(KeyCode.Alpha3))
{
monster.RunAwayFrom(cam.gameObject, 1, 1);
}
if (Input.GetKeyDown(KeyCode.Alpha0))
{
monster.Stop();
}
if (Input.GetKeyDown(KeyCode.Alpha1)) monster.Target(cam.gameObject, true);
if (Input.GetKeyDown(KeyCode.Alpha2)) monster.TargetFlare(cam.gameObject, 1, 1);
if (Input.GetKeyDown(KeyCode.Alpha3)) monster.RunAwayFrom(cam.gameObject, 1, 1);
if (Input.GetKeyDown(KeyCode.Alpha0)) monster.Stop();
}
}
}

View File

@ -1,27 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DummyComponent : MonoBehaviour
{
private Animator anim;
// Start is called before the first frame update
void Start()
private void Start()
{
anim = this.GetComponentInParent<Animator>();
anim = GetComponentInParent<Animator>();
}
// Update is called once per frame
void Update()
private void Update()
{
}
private void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.GetComponent<BulletComponent>() != null)
{
anim.Play("DummyFall");
}
if (collision.gameObject.GetComponent<BulletComponent>() != null) anim.Play("DummyFall");
}
}
}

View File

@ -1,26 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MonsterComponent : MonoBehaviour
{
[SerializeField] private float attackDamage = 1f;
[SerializeField]
private float attackDamage = 1f;
public float AttackDamage { get { return this.attackDamage; } }
[SerializeField] private bool shakeCameraOnHit = true;
public float AttackDamage => attackDamage;
public bool ShakeCameraOnHit => shakeCameraOnHit;
[SerializeField]
private bool shakeCameraOnHit = true;
public bool ShakeCameraOnHit { get { return this.shakeCameraOnHit; } }
// Start is called before the first frame update
void Start()
private void Start()
{
}
// Update is called once per frame
void Update()
private void Update()
{
}
}
}

View File

@ -1,38 +1,32 @@
using UnityEngine;
using System;
using System.Collections;
[RequireComponent(typeof(Animator))]
public class IKControl_Robot : MonoBehaviour
{
public bool ikActive;
public Transform rightHandObj;
public Transform leftHandObj;
public Transform lookObj;
public Transform stepOnObj;
public Transform stepOffObj;
protected Animator animator;
public bool ikActive = false;
public Transform rightHandObj = null;
public Transform leftHandObj = null;
public Transform lookObj = null;
public Transform stepOnObj = null;
public Transform stepOffObj = null;
void Start()
private void Start()
{
animator = GetComponent<Animator>();
transform.Rotate(0, 90, 0);
}
//a callback for calculating IK
void OnAnimatorIK()
private void OnAnimatorIK()
{
if (animator)
{
//if the IK is active, set the position and rotation directly to the goal.
if (ikActive)
{
// Set the look target position, if one has been assigned
if (lookObj != null)
{
@ -48,6 +42,7 @@ public class IKControl_Robot : MonoBehaviour
animator.SetIKPosition(AvatarIKGoal.RightHand, rightHandObj.position);
animator.SetIKRotation(AvatarIKGoal.RightHand, rightHandObj.rotation);
}
if (leftHandObj != null)
{
animator.SetIKPositionWeight(AvatarIKGoal.LeftHand, 1);
@ -55,22 +50,22 @@ public class IKControl_Robot : MonoBehaviour
animator.SetIKPosition(AvatarIKGoal.LeftHand, leftHandObj.position);
animator.SetIKRotation(AvatarIKGoal.LeftHand, leftHandObj.rotation);
}
if(stepOnObj != null)
if (stepOnObj != null)
{
animator.SetIKPositionWeight(AvatarIKGoal.LeftFoot, 1);
animator.SetIKRotationWeight(AvatarIKGoal.LeftFoot, 1);
animator.SetIKPosition(AvatarIKGoal.LeftFoot,stepOnObj.position);
animator.SetIKRotation(AvatarIKGoal.LeftFoot,stepOnObj.rotation);
animator.SetIKPosition(AvatarIKGoal.LeftFoot, stepOnObj.position);
animator.SetIKRotation(AvatarIKGoal.LeftFoot, stepOnObj.rotation);
}
if(stepOffObj!= null) {
if (stepOffObj != null)
{
animator.SetIKPositionWeight(AvatarIKGoal.RightFoot, 1);
animator.SetIKRotationWeight(AvatarIKGoal.RightFoot, 1);
animator.SetIKPosition(AvatarIKGoal.RightFoot, stepOffObj.position);
animator.SetIKRotation(AvatarIKGoal.RightFoot, stepOffObj.rotation);
}
}
//if the IK is not active, set the position and rotation of the hand and head back to the original position
@ -87,8 +82,6 @@ public class IKControl_Robot : MonoBehaviour
animator.SetIKPositionWeight(AvatarIKGoal.RightFoot, 0);
animator.SetIKRotationWeight(AvatarIKGoal.RightFoot, 0);
}
}
}

View File

@ -1,24 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.VFX;
public class RobotMouthAnimator : MonoBehaviour
{
[SerializeField] private VisualEffect fireEffect;
[SerializeField] private Light fireLight;
private Animator anim;
[SerializeField]
private VisualEffect fireEffect;
[SerializeField]
private Light fireLight;
// Start is called before the first frame update
void Start()
private void Start()
{
anim = GetComponent<Animator>();
fireLight.gameObject.SetActive(false);
}
// Update is called once per frame
void Update()
private void Update()
{
if (Input.GetKeyDown(KeyCode.Return))
{
@ -26,21 +26,19 @@ public class RobotMouthAnimator : MonoBehaviour
if (anim.GetBool("FlapsOpen"))
{
StartCoroutine(WaitToFire());
}
else
{
fireEffect.Stop();
fireLight.gameObject.SetActive(false);
}
}
}
private IEnumerator WaitToFire()
{
yield return new WaitForSeconds(1.5f);
fireEffect.Play();
fireLight.gameObject.SetActive(true);
}
}
}

View File

@ -1,74 +1,62 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.VFX;
[ExecuteAlways]
public class SwarmAnimator : MonoBehaviour
{
[SerializeField]
private VisualEffect vfx;
[SerializeField] private VisualEffect vfx;
private Vector3 currentPosition;
private Vector3 previousPosition;
[SerializeField]
private Rigidbody rb;
[SerializeField] private Rigidbody rb;
//[SerializeField]
//private string parameterName = "DeltaVector";
[SerializeField]
private Vector3 avoidancePosDefault;
[SerializeField] private Vector3 avoidancePosDefault;
[SerializeField]
private float explodeDuration = 1.0f;
private float dur = 0f;
private bool isExploding = false;
[SerializeField] private float explodeDuration = 1.0f;
private Vector3 currentPosition;
private float dur;
private bool isExploding;
private Vector3 previousPosition;
// Start is called before the first frame update
void Start()
private void Start()
{
}
// Update is called once per frame
void Update()
private void Update()
{
previousPosition = currentPosition;
currentPosition = transform.position;
Vector3 velocity = (currentPosition - previousPosition) ;
var velocity = currentPosition - previousPosition;
vfx.SetVector3("DeltaVector", velocity);
if (Input.GetKeyDown(KeyCode.Space))
{
Explode();
}
if (Input.GetKeyDown(KeyCode.Space)) Explode();
if (isExploding)
{
if(dur> explodeDuration)
{
StopExplode();
}
if (dur > explodeDuration) StopExplode();
dur += Time.deltaTime;
}
}
void Explode()
private void FixedUpdate()
{
}
private void Explode()
{
vfx.SetVector3("Avoid", transform.position);
this.isExploding = true;
isExploding = true;
dur = 0;
//Wait a sec then stop.
}
void StopExplode()
private void StopExplode()
{
vfx.SetVector3("Avoid", avoidancePosDefault);
this.isExploding = false;
isExploding = false;
vfx.Stop();
}
private void FixedUpdate()
{
}
}
}