Beispiel #1
0
        protected override FiringSolution?FindFiringSolution(GameObject target)
        {
            var projectile   = ProjectilePrefab.GetComponent <FlakProjectile>();
            var minimumRange = projectile.MinimumFuseRange;

            var targetPosition = target.transform.position;
            var delta          = targetPosition - transform.position;
            var distance       = delta.magnitude;
            var direction      = delta / distance;

            if (distance < minimumRange)
            {
                return(null);
            }

            var targetSolution = _turretBase.FindSolution(direction);

            if (targetSolution == null)
            {
                return(null);                //< even if we wanted to, we're not able to point our gun at this solution...
            }
            return(new FiringSolution
            {
                TargetPosition = targetPosition,
                FiringDirection = direction,
                InterceptionDistance = distance
            });
        }
    /// <summary>
    /// Spawns a projectile in the field.
    ///
    /// If absoluteWorldCoord is set to false, location specifies a relative position in the field. 0.0 = left/bottom, 1.0 = right/top. Values greater than 1 or less than 0 spawn
    /// outside of of the camera view.
    /// </summary>
    /// <param name="prefab">Prefab for the spawned projectile, describes the visuals, size, and hitbox characteristics of the prefab.</param>
    /// <param name="location">The location within the field to spawn the projectile.</param>
    /// <param name="rotation">Rotation.</param>
    /// <param name="absoluteWorldCoord">If set to <c>true</c>, <c>location</c> is in absolute world coordinates relative to the bottom right corner of the game plane.</param>
    /// <param name="extraControllers">Extra ProjectileControllers to change the behavior of the projectile.</param>
    public Projectile SpawnProjectile(ProjectilePrefab prefab, Vector2 location, float rotation, CoordinateSystem coordSys = CoordinateSystem.Screen, ProjectileController[] extraControllers = null)
    {
        Vector3 worldLocation = Vector3.zero;

        switch (coordSys)
        {
        case CoordinateSystem.Screen:
            worldLocation = WorldPoint(new Vector3(location.x, location.y, gamePlaneDistance));
            break;

        case CoordinateSystem.FieldRelative:
            worldLocation = BottomLeft + new Vector3(location.x, location.y, 0f);
            break;

        case CoordinateSystem.AbsoluteWorld:
            worldLocation = location;
            break;
        }
        Projectile projectile = (Projectile)bulletPool.Get(prefab);

        projectile.Transform.position = worldLocation;
        projectile.Transform.rotation = Quaternion.Euler(0f, 0f, rotation);
        projectile.Active             = true;
        return(projectile);
    }
Beispiel #3
0
 /// <summary>
 /// Fires the linear bullet.
 /// </summary>
 /// <returns>The linear bullet.</returns>
 /// <param name="bulletType">Bullet type.</param>
 /// <param name="location">Location.</param>
 /// <param name="rotation">Rotation.</param>
 /// <param name="velocity">Velocity.</param>
 protected Projectile FireLinearBullet(ProjectilePrefab bulletType,
                                       Vector2 location,
                                       float rotation,
                                       float velocity)
 {
     return(FireCurvedBullet(bulletType, location, rotation, velocity, 0f));
 }
Beispiel #4
0
    protected virtual void SpawnProjectile(Step step)
    {
        ProjectilePrefab projectile = ProjectilePrefabs[step.projectile.code];
        GameObject       inst       = Instantiate(projectile.prefab, transform.position + transform.TransformDirection(projectile.offset), transform.rotation);
        // 임시
        BulletBehaviour bullet = inst.GetComponent <BulletBehaviour>();

        bullet.Fire(projectile.speed, projectile.lifeTime);
        stepStarted  = false;
        stepFinished = true;
    }
Beispiel #5
0
    /// <summary>
    /// Fires the curved bullet.
    /// </summary>
    /// <returns>The curved bullet.</returns>
    /// <param name="bulletType">Bullet type.</param>
    /// <param name="location">Location.</param>
    /// <param name="rotation">Rotation.</param>
    /// <param name="velocity">Velocity.</param>
    /// <param name="angularVelocity">Angular velocity.</param>
    protected Projectile FireCurvedBullet(ProjectilePrefab bulletType,
                                          Vector2 location,
                                          float rotation,
                                          float velocity,
                                          float angularVelocity)
    {
        Projectile bullet = targetField.SpawnProjectile(bulletType, location, rotation);

        bullet.Velocity        = velocity;
        bullet.AngularVelocity = angularVelocity;
        return(bullet);
    }
 protected override FiringSolution?FindFiringSolution(GameObject target)
 {
     return(FiringSolution.FindSolution(gameObject, ProjectilePrefab.GetComponent <ProjectileComponent>(), target));
 }