Esempio n. 1
0
    private void MoveAsRay(float delta)
    {
        Transform t       = GlobalTransform;
        Vector3   origin  = t.origin;
        Vector3   forward = -t.basis.z;
        Vector3   dest    = origin;

        dest += (forward * _def.launchSpeed) * delta;
        uint mask = uint.MaxValue;
        PhysicsDirectSpaceState space = GetWorld().DirectSpaceState;

        Godot.Collections.Array arr = null;
        if (_ignoreBody != null)
        {
            arr = new Godot.Collections.Array();
            arr.Add(_ignoreBody);
        }
        Dictionary hitResult = space.IntersectRay(origin, dest, arr, mask);

        if (hitResult.Keys.Count > 0)
        {
            _touch.damage    = _def.damage;
            _touch.teamId    = 0;
            _touch.touchType = TouchType.Bullet;
            IActorProvider actorProvider = hitResult["collider"] as IActorProvider;
            if (actorProvider != null)
            {
                IActor actor = actorProvider.GetActor();
                if (actor != null)
                {
                    TouchResponseData response = actor.ActorTouch(_touch);
                    Console.WriteLine($"Prj hit actor for {response.damageTaken}");
                }
                else
                {
                    Console.WriteLine($"Prj hit provider but actor is null!");
                }
            }
            else
            {
                //Node hitObj = (hitResult["collider"] as Node);
                //Console.WriteLine($"Prj hit non-actor node {hitObj.Name}");
            }
            Vector3  gfxOrigin = (Vector3)hitResult["position"];
            GFXQuick gfx       = Main.i.factory.SpawnGFX(GameFactory.Path_GFXImpact);
            gfx.Spawn(gfxOrigin);
            Die();
            return;
        }
        t.origin        = dest;
        GlobalTransform = t;
    }