got a few questions on coding, i’ll just ask one at a time.
I would like, when the player walks in the field of view of the enemy, the enemy rushes at the player and then disappears, causing a raise in heart rate by 20 BPM.
I think events, PlayerInViewEvent, and RateIncreaseEvent are what would work for this. but i do not know how to get that all to work in the code, and i don’t know if those are even the best way to go about this. Can i please get some coding help.
here is the code i have so far.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HeartRate : MonoBehaviour {
public GameObject Player;
public GameObject Enemy;
float heartRateBase = 80; // 80 BPM
public float heartRate = 100;
float safeDistance = 5; // distance away form the enemy where heart rate goes down
float relaxRate = 0.005f; // how fast the player recovers
float stressRate = 0.05f;// The closer the plauer is to the enemy the more it will increase
void FixedUpdate()
{
// Find distance from enemy
float dist = Vector3.Distance (Player.transform.position, Enemy.transform.position);
// Check to see if player is safe
if (dist > safeDistance)
{
// Decrease player heart Rate
if (heartRate > heartRateBase)
heartRate -= relaxRate;
}
else
{
// Increase the players heart rate depending on how close they are
float rate = 1 - dist / safeDistance;
heartRate += stressRate * rate;
}
}
}