예제 #1
0
        /// <summary>
        /// Fire a bullet in the shape of a line that instantly hits the target.
        /// </summary>
        protected void FireHitScan()
        {
            Raycast   ray = new Raycast(CurrentPlayer.Position, CurrentPlayer.MoveTarget, 1024.0);
            RayResult res = CurrentPlayer.CurrentGame.FindEnemyOnRay(ray);

            if (res.Hit != null)
            {
                if (res.Hit is Enemy)
                {
                    res.Hit.TakeDamage(CurrentPlayer.EquippedTool.Damage);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Return true if ray intersects an enemy
        /// </summary>
        /// <param name="part">The enemy</param>
        /// <returns></returns>
        public RayResult Intersects(Enemy part)
        {
            RayResult res   = new RayResult();
            Vector    clPos = ClosestPoint(part.Position);

            if (part.IsInside(clPos))
            {
                res.Hit      = part;
                res.Position = clPos; //TODO: NOT RIGHT??
                return(res);
            }
            return(res);
        }
예제 #3
0
        public RayResult FindEnemyOnRay(Raycast ray)
        {
            RayResult res = new RayResult();

            foreach (Enemy e in Enemies)
            {
                res = ray.Intersects(e);
                if (res.Hit != null)
                {
                    Console.WriteLine(res.Hit.ToString());
                    return(res);
                }
            }
            Console.WriteLine("Pos: " + res.Position.ToString());
            Console.WriteLine("Hit: null");
            return(res);
        }