void updateChaseDir() { if (sheepChaseTarget == null) { randomNextActivity(); return; } // check whether we can transition to abduction float dist = (sheepChaseTarget.transform.position - transform.position).magnitude; //Debug.Log(string.Format("start abduction? dist is {0}", dist)); if (dist <= abductStartDist) { state = AngelState.ABDUCTING_SHEEP; startAbducting(); return; } timeoutChaseRedirect = timeoutChaseRedirectInitial; // compute goal Vector3 goal = sheepChaseTarget.transform.position; goal.y += levitationHeight; // move towards goal Vector3 chaseDir = goal - transform.position; chaseDir /= chaseDir.magnitude; rb.velocity = chaseDir * chaseSpeed; }
void startChasing() { // Find random sheep within sheepChaseDist int numSheepConsidered = 0; if (hsm.sheepDict.Count > 0) { foreach (int index in hsm.sheepDict.Keys) { GameObject sheep = hsm.sheepDict[index]; float distance = (sheep.transform.position - transform.position).magnitude; if (distance < sheepChaseDist) { numSheepConsidered++; if ((numSheepConsidered == 1) || (Random.value < (1 / numSheepConsidered))) { sheepChaseTarget = sheep; } } } } // if no nearby sheep, just drift if (numSheepConsidered == 0) { state = AngelState.DRIFTING; startDrifting(); return; } timeoutChaseStop = timeoutChaseStopInitial; updateChaseDir(); }
void randomNextActivity() { float randomNum = Random.value; if (randomNum < driftProbability) { state = AngelState.DRIFTING; startDrifting(); } else if (randomNum < driftProbability + chaseProbability) { state = AngelState.CHASING_SHEEP; startChasing(); } else { state = AngelState.ATTACKING_PLAYER; startSpontaneouslyAttacking(); } }
private Vector3 playerTargetDisplacement = new Vector3(0, 5, 0); // bolts are aimed at player's position plus this // Start is called before the first frame update void Start() { spawnPoint = transform.position; rb = gameObject.GetComponent <Rigidbody>(); hsm = FindObjectOfType <hellSceneManager>(); // create abduction beam lineRenderer = gameObject.AddComponent <LineRenderer>(); lineRenderer.material = abductBeamMat; lineRenderer.widthMultiplier = beamWidth; Gradient gradient = new Gradient(); gradient.SetKeys( new GradientColorKey[] { new GradientColorKey(beamStartCol, 0.0f), new GradientColorKey(beamEndCol, 1.0f) }, new GradientAlphaKey[] { new GradientAlphaKey(beamStartAlpha, 0.0f), new GradientAlphaKey(beamEndAlpha, 1.0f) } ); lineRenderer.colorGradient = gradient; lineRenderer.positionCount = 0; HealthScript.AddHealthScript(gameObject, startHealth, .6f * transform.localScale.x, null, WoundAction, DeathFunction); state = AngelState.JUST_CREATED; }
void alarmTriggered() { state = AngelState.ATTACKING_PLAYER; startAttacking(); }