GetAimDir() public method

Get the direction to aim that bullet
public GetAimDir ( ) : float
return float
Ejemplo n.º 1
0
        private float GetDirection(Bullet bullet)
        {
            //How do we want to change direction?
            float delta = 0.0f;

            switch (ChangeType)
            {
            case ENodeType.sequence:
            {
                //We are going to add this amount to the direction every frame
                delta = NodeDirection;
            }
            break;

            case ENodeType.absolute:
            {
                //We are going to go in the direction we are given, regardless of where we are pointing right now
                delta = NodeDirection - bullet.Direction;
            }
            break;

            case ENodeType.relative:
            {
                //The direction change will be relative to our current direction
                delta = NodeDirection;
            }
            break;

            default:
            {
                //the direction change is to aim at the enemy
                delta = ((NodeDirection + bullet.GetAimDir()) - bullet.Direction);
            }
            break;
            }

            //keep the direction between -180 and 180
            delta = MathHelper.WrapAngle(delta);

            //The sequence type of change direction is unaffected by the duration
            if (ChangeType == ENodeType.relative)
            {
                //Divide by the duration so we ease into the direction change
                delta /= Duration;
            }
            //The sequence type of change direction is unaffected by the duration
            else if (ChangeType != ENodeType.sequence)
            {
                //divide by the amount fo time remaining
                delta /= Duration - RunDelta;
            }

            return(delta);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// this sets up the task to be run.
        /// </summary>
        /// <param name="bullet">Bullet.</param>
        protected override void SetupTask(Bullet bullet)
        {
            //get the direction to shoot the bullet

            //is this the first time it has ran?  If there isn't a sequence node, we don't care!
            if (InitialRun || (null == SequenceDirectionTask))
            {
                //do we have an initial direction node?
                if (null != InitialDirectionTask)
                {
                    //Set the fire direction to the "initial" value
                    float newBulletDirection = InitialDirectionTask.GetNodeValue() * (float)Mathf.PI / 180.0f;
                    switch (InitialDirectionTask.Node.NodeType)
                    {
                    case ENodeType.absolute:
                    {
                        //the new bullet points right at a particular direction
                        FireDirection = newBulletDirection;
                    }
                    break;

                    case ENodeType.relative:
                    {
                        //the new bullet direction will be relative to the old bullet
                        FireDirection = newBulletDirection + bullet.Direction;
                    }
                    break;

                    default:
                    {
                        //aim the bullet at the player
                        FireDirection = newBulletDirection + bullet.GetAimDir();
                    }
                    break;
                    }
                }
                else
                {
                    //There isn't an initial direction task, so just aim at the bad guy.
                    //aim the bullet at the player
                    FireDirection = bullet.GetAimDir();
                }
            }
            else if (null != SequenceDirectionTask)
            {
                //else if there is a sequence node, add the value to the "shoot direction"
                FireDirection += SequenceDirectionTask.GetNodeValue() * (float)Mathf.PI / 180.0f;
            }

            //Set the speed to shoot the bullet

            //is this the first time it has ran?  If there isn't a sequence node, we don't care!
            if (InitialRun || (null == SequenceSpeedTask))
            {
                //do we have an initial speed node?
                if (null != InitialSpeedTask)
                {
                    //set the shoot speed to the "initial" value.
                    float newBulletSpeed = InitialSpeedTask.GetNodeValue();
                    switch (InitialSpeedTask.Node.NodeType)
                    {
                    case ENodeType.relative:
                    {
                        //the new bullet speed will be relative to the old bullet
                        FireSpeed = newBulletSpeed + bullet.Speed;
                    }
                    break;

                    default:
                    {
                        //the new bullet shoots at a predeterminde speed
                        FireSpeed = newBulletSpeed;
                    }
                    break;
                    }
                }
                else
                {
                    //there is no initial speed task, use the old dude's speed
                    FireSpeed = bullet.Speed;
                }
            }
            else if (null != SequenceSpeedTask)
            {
                //else if there is a sequence node, add the value to the "shoot direction"
                FireSpeed += SequenceSpeedTask.GetNodeValue();
            }

            //make sure the direction is between 0 and 359
            while ((2.0f * Mathf.PI) <= FireDirection)
            {
                FireDirection -= (2.0f * (float)Mathf.PI);
            }
            while (0.0f > FireDirection)
            {
                FireDirection += (2.0f * (float)Mathf.PI);
            }

            //make sure we don't overwrite the initial values if we aren't supposed to
            NumTimesInitialized++;
        }
        /// <summary>
        /// this sets up the task to be run.
        /// </summary>
        /// <param name="bullet">Bullet.</param>
        protected override void SetupTask(Bullet bullet)
        {
            //set the time length to run this dude
            Duration = Node.GetChildValue(ENodeName.term, this);

            //check for divide by 0
            if (0.0f == Duration)
            {
                Duration = 1.0f;
            }

            //Get the amount to change direction from the nodes
            DirectionNode dirNode = Node.GetChild(ENodeName.direction) as DirectionNode;
            float value = dirNode.GetValue(this) * (float)Mathf.PI / 180.0f; //also make sure to convert to radians

            //How do we want to change direction?
            ENodeType changeType = dirNode.NodeType;
            switch (changeType)
            {
                case ENodeType.sequence:
                {
                    //We are going to add this amount to the direction every frame
                    DirectionChange = value;
                }
                break;

                case ENodeType.absolute:
                {
                    //We are going to go in the direction we are given, regardless of where we are pointing right now
                    DirectionChange = value - bullet.Direction;
                }
                break;

                case ENodeType.relative:
                {
                    //The direction change will be relative to our current direction
                    DirectionChange = value;
                }
                break;

                default:
                {
                    //the direction change is to aim at the enemy
                    DirectionChange = ((value + bullet.GetAimDir()) - bullet.Direction);
                }
                break;
            }

            //keep the direction between 0 and 360
            if (DirectionChange > Mathf.PI)
            {
                DirectionChange -= 2 * (float)Mathf.PI;
            }
            else if (DirectionChange < -Mathf.PI)
            {
                DirectionChange += 2 * (float)Mathf.PI;
            }

            //The sequence type of change direction is unaffected by the duration
            if (changeType != ENodeType.sequence)
            {
                //Divide by the duration so we ease into the direction change
                DirectionChange /= Duration;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// this sets up the task to be run.
        /// </summary>
        /// <param name="bullet">Bullet.</param>
        protected override void SetupTask(Bullet bullet)
        {
            //get the direction to shoot the bullet

            //is this the first time it has ran?  If there isn't a sequence node, we don't care!
            if (InitialRun || (null == SequenceDirectionTask))
            {
                //do we have an initial direction node?
                if (null != InitialDirectionTask)
                {
                    //Set the fire direction to the "initial" value
                    float newBulletDirection = InitialDirectionTask.GetNodeValue(bullet) * (float)Math.PI / 180.0f;
                    switch (InitialDirectionTask.Node.NodeType)
                    {
                        case ENodeType.absolute:
                        {
                            //the new bullet points right at a particular direction
                            FireDirection = newBulletDirection;
                        }
                        break;

                        case ENodeType.relative:
                        {
                            //the new bullet direction will be relative to the old bullet
                            FireDirection = newBulletDirection + bullet.Direction;
                        }
                        break;

                        default:
                        {
                            //aim the bullet at the player
                            FireDirection = newBulletDirection + bullet.GetAimDir();
                        }
                        break;
                    }
                }
                else
                {
                    //There isn't an initial direction task, so just aim at the bad guy.
                    //aim the bullet at the player
                    FireDirection = bullet.GetAimDir();
                }
            }
            else if (null != SequenceDirectionTask)
            {
                //else if there is a sequence node, add the value to the "shoot direction"
                FireDirection += SequenceDirectionTask.GetNodeValue(bullet) * (float)Math.PI / 180.0f;
            }

            //Set the speed to shoot the bullet

            //is this the first time it has ran?  If there isn't a sequence node, we don't care!
            if (InitialRun || (null == SequenceSpeedTask))
            {
                //do we have an initial speed node?
                if (null != InitialSpeedTask)
                {
                    //set the shoot speed to the "initial" value.
                    float newBulletSpeed = InitialSpeedTask.GetNodeValue(bullet);
                    switch (InitialSpeedTask.Node.NodeType)
                    {
                        case ENodeType.relative:
                        {
                            //the new bullet speed will be relative to the old bullet
                            FireSpeed = newBulletSpeed + bullet.Speed;
                        }
                        break;

                        default:
                        {
                            //the new bullet shoots at a predeterminde speed
                            FireSpeed = newBulletSpeed;
                        }
                        break;
                    }
                }
                else
                {
                    //there is no initial speed task, use the old dude's speed
                    FireSpeed = bullet.Speed;
                }
            }
            else if (null != SequenceSpeedTask)
            {
                //else if there is a sequence node, add the value to the "shoot direction"
                FireSpeed += SequenceSpeedTask.GetNodeValue(bullet);
            }

            //make sure the direction is between 0 and 359
            while (FireDirection > Math.PI)
            {
                FireDirection -= (2.0f * (float)Math.PI);
            }
            while (-Math.PI > FireDirection)
            {
                FireDirection += (2.0f * (float)Math.PI);
            }

            //make sure we don't overwrite the initial values if we aren't supposed to
            NumTimesInitialized++;
        }
        /// <summary>
        /// this sets up the task to be run.
        /// </summary>
        /// <param name="bullet">Bullet.</param>
        protected override void SetupTask(Bullet bullet)
        {
            //set the time length to run this dude
            startDuration = Node.GetChildValue(ENodeName.term, this);

            //check for divide by 0
            if (0.0f == startDuration)
            {
                startDuration = 1.0f;
            }

            // Remove the 60 FPS limit (or at least try, ChangeDirection is very, very sensitive to frame variation)
            float ratio = TimeFix.Framerate / 60f;

            startDuration *= ratio;

            Duration = startDuration;

            //Get the amount to change direction from the nodes
            DirectionNode dirNode = Node.GetChild(ENodeName.direction) as DirectionNode;
            float         value   = dirNode.GetValue(this) * (float)Mathf.PI / 180.0f;   //also make sure to convert to radians

            //How do we want to change direction?
            ENodeType changeType = dirNode.NodeType;

            switch (changeType)
            {
            case ENodeType.sequence:
            {
                //We are going to add this amount to the direction every frame
                DirectionChange = value;
            }
            break;

            case ENodeType.absolute:
            {
                //We are going to go in the direction we are given, regardless of where we are pointing right now
                DirectionChange = value - bullet.Direction;
            }
            break;

            case ENodeType.relative:
            {
                //The direction change will be relative to our current direction
                DirectionChange = value;
            }
            break;

            default:
            {
                //the direction change is to aim at the enemy
                DirectionChange = ((value + bullet.GetAimDir()) - bullet.Direction);
            }
            break;
            }

            //keep the direction between 0 and 360
            if (DirectionChange > Mathf.PI)
            {
                DirectionChange -= 2 * (float)Mathf.PI;
            }
            else if (DirectionChange < -Mathf.PI)
            {
                DirectionChange += 2 * (float)Mathf.PI;
            }

            //The sequence type of change direction is unaffected by the duration
            if (changeType != ENodeType.sequence)
            {
                //Divide by the duration so we ease into the direction change
                DirectionChange /= Duration;
            }
        }
Ejemplo n.º 6
0
        private float GetDirection(Bullet bullet)
        {
            //How do we want to change direction?
            float direction = 0.0f;
            switch (ChangeType)
            {
                case ENodeType.sequence:
                {
                    //We are going to add this amount to the direction every frame
                    direction = NodeDirection;
                }
                break;

                case ENodeType.absolute:
                {
                    //We are going to go in the direction we are given, regardless of where we are pointing right now
                    direction = NodeDirection - bullet.Direction;
                }
                break;

                case ENodeType.relative:
                {
                    //The direction change will be relative to our current direction
                    direction = NodeDirection;
                }
                break;

                default:
                {
                    //the direction change is to aim at the enemy
                    direction = ((NodeDirection + bullet.GetAimDir()) - bullet.Direction);
                }
                break;
            }

            //keep the direction between -180 and 180
            direction = MathHelper.WrapAngle(direction);

            //The sequence type of change direction is unaffected by the duration
            if (ChangeType == ENodeType.absolute)
            {
                //divide by the amount fo time remaining
                direction /= Duration - RunDelta;
            }
            else if (ChangeType != ENodeType.sequence)
            {
                //Divide by the duration so we ease into the direction change
                direction /= Duration;
            }

            return direction;
        }