public override void CustomCreate(ProjectileComponent component) { targetObject = component.data.Entity.GetFaction() == Entity.Faction.enemy ? GameManager.Player.gameObject : GameManager.Boss.gameObject; wasClose = false; curDivergence = 0f; homingScale = (float)component.data.Speed / 7f; }
/// <summary> /// Generates a new GameObject with a ProjectileComponent that references this /// data object. /// </summary> /// <returns>The ProjectileComponent added to the new GameObject.</returns> public ProjectileComponent Create() { Profiler.BeginSample("Projectile.Create"); Profiler.BeginSample("Projectile.Create GameObject Instantiate"); // Create new GameObject //GameObject newObj = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Projectile")); GameObject newObj = ProjectileManager.Checkout(); Profiler.EndSample(); Profiler.BeginSample("Projectile.Create Component Instantiate"); // Create a new Projectile component ProjectileComponent projectile = newObj.GetComponent <ProjectileComponent>(); Profiler.EndSample(); Profiler.BeginSample("Projectile.Create data Clone()"); // Make a memberwise clone of the most derived type projectile.data = Clone(); Profiler.EndSample(); Profiler.BeginSample("Projectile.Create data Initialize()"); // Do the initialization (resolve null variables -> live variables) projectile.Initialize(); Profiler.EndSample(); Profiler.BeginSample("Projectile.Create data CustomCreate()"); // Do any custom derived initialization logic (you can access the component now) projectile.data.CustomCreate(projectile); Profiler.EndSample(); Profiler.EndSample(); return(projectile); }
public override void CustomUpdate(ProjectileComponent component) { if ((component.transform.position - GameManager.Player.transform.position).magnitude < 5f) { GameObject.Destroy(component.gameObject); } if (component.currentTime > count / numSpawners) { count++; new Projectile { Start = component.transform.position, MaxTime = initialMaxTime - component.currentTime, Size = Size.SMALL, Speed = BossCore.Speed.FROZEN }.Create(); } }
public override void CustomUpdate(ProjectileComponent component) { Quaternion rot = Quaternion.AngleAxis(Time.deltaTime * curveAmount, Vector3.up); //body.velocity = rot * body.velocity; Velocity = rot * Velocity; if (leavesTrail) { if (component.currentTime > count / numSpawners) { count++; ProjectileComponent newComp = new Projectile(Entity) { Start = component.transform.position, MaxTime = MaxTime - component.currentTime, Size = Size.SMALL, Speed = BossCore.Speed.FROZEN }.Create(); } } }
public override void CustomUpdate(ProjectileComponent component) { Vector3 idealVelocity = ((float)Speed) * (targetObject.transform.position - component.transform.position).normalized; float idealRotation = Vector3.SignedAngle(idealVelocity, Velocity, Vector3.up); float distance = Vector3.Distance(targetObject.transform.position, component.transform.position); if (!wasClose && distance < 10f) { wasClose = true; } if ((wasClose && distance > 10f) || curDivergence >= maxDivergence) { return; } float feathering = 1f; if (distance > 10f && distance < 25f) { feathering = (25f - distance) / 15f; } float distanceScale = 1f; //distance < 15f ? 1 + ((15 - distance) / 5f) : 1f; if (Mathf.Abs(idealRotation) >= 10f && Mathf.Abs(idealRotation) < 120f) { Quaternion rot = Quaternion.AngleAxis(-Mathf.Sign(idealRotation) * homingScale * feathering * distanceScale, Vector3.up); //body.velocity = rot * body.velocity; Velocity = rot * Velocity; //body.velocity = (distanceScale * (float)speed) * body.velocity.normalized; Velocity = (distanceScale * (float)Speed) * Velocity.normalized; curDivergence += homingScale; } }
/// <summary> /// This method is called at the end of every Update() call. When overridden, /// this can be used to specify custom movement. /// </summary> /// <param name="component">The ProjectileComponent of this active GameObject.</param> public virtual void CustomUpdate(ProjectileComponent component) { }
public override void CustomCreate(ProjectileComponent component) { // Make the target the player position, but at a radius of 100. // This prevents "bunching" around the true target. initialTarget = (100f / component.data.Target.GetValue().magnitude) * component.data.Target.GetValue(); }
public override void CustomUpdate(ProjectileComponent component) { Velocity = (float)Speed * func(component.currentTime) * initialTarget; }
public override void CustomCreate(ProjectileComponent component) { component.currentTime = 0; initialTarget = (Target.GetValue() - Start.GetValue()).normalized; }