Esempio n. 1
0
    public Vector3 GetTeleportLocation()
    {
        // get weighted sum of all
        Vector3 resultant     = Vector3.Zero;
        Spatial detector      = GetNode <Spatial>("Detectors");
        RayCast bottomRaycast = detector.GetNode <RayCast>("bottom");

        bottomRaycast.ForceRaycastUpdate();
        if (!bottomRaycast.IsColliding())
        {
            Util.DrawSphere(bottomRaycast.GetCollisionPoint(), detector);
        }

        foreach (RayCast cast in _detectorList)
        {
            cast.ForceRaycastUpdate();
            if (cast.IsColliding())
            {
                // get collision point in local coordinates to detector spatial in middle of sword
                Vector3 collisionVector = cast.Transform.XformInv(cast.GetCollisionPoint());
                resultant += cast.GetCollisionNormal() * (1 - Mathf.Min(collisionVector.Length(), _minDetectorWeight));
            }
        }

        // return average of normals
        return(Transform.origin + resultant.Normalized());
    }
Esempio n. 2
0
    protected virtual void Anim_Hit()
    {
        if (ray == null)
        {
            return;
        }

        ray.CastTo = Vector3.Forward;
        ray.ForceRaycastUpdate();

        if (ray.IsColliding() && ray.GetCollider() is IDamageable)
        {
            (ray.GetCollider() as IDamageable).AttemptDamage();
        }
    }
Esempio n. 3
0
        private void FireBullet()
        {
            if (UseRaycast)
            {
                _nodeRayCast.LookAt(_currentTarget.GlobalTransform.origin
                                    + new Vector3(0, PlayerHeight, 0), new Vector3(0, 1, 0));
                _nodeRayCast.ForceRaycastUpdate();
                if (_nodeRayCast.IsColliding())
                {
                    var body = _nodeRayCast.GetCollider();
                    if (body.HasMethod("BulletHit"))
                    {
                        body.Call("BulletHit", TurretDamageRaycast, _nodeRayCast.GetCollisionPoint());
                    }
                }
            }
            else
            {
                var clone     = _bulletScene.Instance <Bullet>();
                var sceneRoot = GetTree().Root.GetChildren()[0] as Node;
                if (sceneRoot == null)
                {
                    return;
                }
                sceneRoot.AddChild(clone);
                clone.GlobalTransform = GetNode <Spatial>("Head/Barrel_End").GlobalTransform;
                clone.Scale           = new Vector3(8, 8, 8);
                clone.BulletDamage    = TurretDamageBullet;
                clone.BulletSpeed     = 60;
            }

            GetNode <Globals>("/root/Globals").PlaySound("Pistol_shot", false, GlobalTransform.origin);
            _ammoInTurret -= 1;

            _nodeFlashOne.Visible = true;
            _nodeFlashTwo.Visible = true;

            _flashTimer = FlashTime;
            _fireTimer  = FireTime;

            if (_ammoInTurret <= 0)
            {
                _ammoReloadTimer = AmmoReloadTime;
            }
        }
Esempio n. 4
0
    public void FireBullet()
    {
        if (_useRaycast)
        {
            _nodeRaycast.LookAt(_currentKinematic.GlobalTransform.origin + new Vector3(0, _playerHeight, 0), new Vector3(0, 1, 0));

            _nodeRaycast.ForceRaycastUpdate();

            if (_nodeRaycast.IsColliding())
            {
                Godot.Object _body = _nodeRaycast.GetCollider();
                if (_body.HasMethod("BulletHit"))
                {
                    _callback = GD.FuncRef(_body, "BulletHit");
                    _callback.CallFunc(_TurretDamageRaycast, _nodeRaycast.GetCollisionPoint());
                }
                _ammoInTurret--;
            }
        }
        else
        {
            StandardBullet _clone     = (StandardBullet)_bulletScene.Instance();
            Node           _sceneRoot = GetTree().Root.GetChild(0);
            _sceneRoot.AddChild(_clone);

            _clone.GlobalTransform = GetNode <Spatial>("Head/Barrel_End").GlobalTransform;
            _clone.Scale           = new Vector3(10, 10, 5);
            _clone.BulletDamage    = _TurretDamageBullet;
            _clone.BulletSpeed     = 5;
            _clone.Gravity         = -0.1f;

            _ammoInTurret--;
        }

        _nodeFlashOne.Visible = true;
        _nodeFlashTwo.Visible = true;

        _flashTimer = _flashTime;
        _fireTimer  = _fireTime;

        if (_ammoInTurret <= 0)
        {
            _ammoReloadTimer = _ammoReloadTime;
        }
    }
Esempio n. 5
0
    private void FireBullet()
    {
        if (UseRaycast == true)
        {
            _nodeRaycast.LookAt(_currentTarget.GlobalTransform.origin + new Vector3(0, PLAYER_HEIGHT, 0), Vector3.Up);
            _nodeRaycast.ForceRaycastUpdate();

            if (_nodeRaycast.IsColliding())
            {
                var body = _nodeRaycast.GetCollider();
                if (body.HasMethod("BulletHit"))
                {
                    (body as Player).BulletHit(TURRET_DAMAGE_RAYCAST, _nodeRaycast.GetCollisionPoint());
                }

                _ammoInTurret -= 1;
            }
        }
        else
        {
            var clone     = _bulletScene.Instance() as BulletScript;
            var sceneRoot = GetTree().Root.GetChildren()[0] as Spatial;
            sceneRoot.AddChild(clone);

            clone.GlobalTransform = GetNode <Spatial>("Head/Barrel_End").GlobalTransform;
            clone.Scale           = new Vector3(8, 8, 8);
            clone.BULLET_DAMAGE   = TURRET_DAMAGE_BULLET;
            clone.BULLET_SPEED    = 60;

            _ammoInTurret -= 1;
        }

        _nodeFlashOne.Visible = true;
        _nodeFlashTwo.Visible = true;

        _flashTimer = FLASH_TIME;
        _fireTimer  = FIRE_TIME;

        if (_ammoInTurret <= 0)
        {
            _ammoReloadTimer = AMMO_RELOAD_TIME;
        }
    }
Esempio n. 6
0
    // instantly move item to floor
    public void MoveToFloor(Projectile obj)
    {
        // trace downwards
        Transform t  = obj.GlobalTransform;
        RayCast   rc = new RayCast();

        obj.AddChild(rc);
        rc.GlobalTransform = t;
        rc.CastTo          = this.Up * -2000;

        rc.ForceRaycastUpdate();

        if (rc.IsColliding())
        {
            t.origin            = rc.GetCollisionPoint();
            obj.GlobalTransform = t;
        }
        obj.RemoveChild(rc);
    }
Esempio n. 7
0
    public override void FireWeapon()
    {
        RayCast Ray = GetNode <RayCast>("Ray_Cast");

        Ray.ForceRaycastUpdate();
        AmmoInWeapon--;

        if (Ray.IsColliding())
        {
            var _body = Ray.GetCollider();

            if (_body != Playernode && _body.HasMethod("BulletHit"))
            {
                _callback = GD.FuncRef(_body, "BulletHit");
                _callback.CallFunc(damage, GlobalTransform);
            }
        }

        Playernode.CreateSound(gunFireSound);
    }
    public void Update(RayCast ray)
    {
        // update manually instead only once per frame in process
        ray.ForceRaycastUpdate();
        var isColliding = ray.IsColliding();

        Visible = isColliding;

        if (isColliding)
        {
            Vector3 collisionPoint  = ray.GetCollisionPoint();
            Vector3 collisionNormal = ray.GetCollisionNormal();

            var transform = this.GlobalTransform;
            transform.origin = collisionPoint + collisionNormal * 0.01f;
            GlobalTransform  = transform;

            LookAt(collisionPoint - collisionNormal, GlobalTransform.basis.y.Normalized());
        }
    }
Esempio n. 9
0
    public override void _PhysicsProcess(float delta)
    {
        Vector3 direction = GetAxisDirection() * speed;

        groundingRay.ForceRaycastUpdate();

        if (groundingRay.IsColliding() && groundingRay.GetCollisionNormal().AngleTo(Vector3.Up) < steepAngle) // check the ngle is not too steep
        {
            Transform t = GlobalTransform;
            t.origin.y      = groundingRay.GetCollisionPoint().y;
            GlobalTransform = t;

            Vector3 normal = groundingRay.GetCollisionNormal();
            Vector3 cross  = GlobalTransform.basis.y.Cross(normal);
            if (cross.Length() > 0.0001f) // If the current player angle is not already at the slope angle
            {
                Rotate(cross.Normalized(), GlobalTransform.basis.y.AngleTo(normal));
            }
            direction = direction.Rotated(Vector3.Up.Cross(normal).Normalized(), Vector3.Up.AngleTo(normal)); // Also rotate the direction
        }
        else
        {
            MoveAndSlide(new Vector3(0, downwardsVelocity, 0));

            // If player is falling, align him
            Vector3 normal = Vector3.Up;
            Vector3 cross  = GlobalTransform.basis.y.Cross(normal);
            if (cross.Length() > 0.0001f) // If the current player angle is not already at the slope angle
            {
                Rotate(cross.Normalized(), GlobalTransform.basis.y.AngleTo(normal));
            }
        }
        MoveAndSlide(direction);
        if (direction.Length() > 0)
        {
            LookAt(GlobalTransform.origin - direction, GlobalTransform.basis.y);
        }
    }
Esempio n. 10
0
    void Shoot(BasePlayer player)
    {
        if (player.ShootEvent != null)
        {
            player.ShootEvent();
        }

        RayCast shoot_cast = player.GetNode("ShootCast") as RayCast;

        shoot_cast.ForceRaycastUpdate();
        if (shoot_cast.IsColliding())
        {
            CollisionObject target = shoot_cast.GetCollider() as CollisionObject;
            if (target is BaseEnemy)
            {
                HitEnemy(player, target as BaseEnemy);
            }
            else
            {
                HitEnvironment(player, target);
            }
        }
    }
Esempio n. 11
0
    private async void ProcessInput(float delta)
    {
        _dir = new Vector3();
        Transform camXform = _camera.GlobalTransform;

        Vector2 inputMovementVector = new Vector2();

        if (Input.IsActionPressed("movement_forwards"))
        {
            inputMovementVector.y += 1; Walk();
        }
        if (Input.IsActionPressed("movement_backwards"))
        {
            inputMovementVector.y -= 1; Walk();
        }
        if (Input.IsActionPressed("movement_left"))
        {
            inputMovementVector.x -= 1; Walk();
        }
        if (Input.IsActionPressed("movement_right"))
        {
            inputMovementVector.x += 1; Walk();
        }

        if (canShoot)
        {
            if (Input.IsActionJustPressed("fire"))
            {
                _raycast.ForceRaycastUpdate();
                canShoot = false;
                pistolAnim.Play("player.shoot");
                gunAudio.PitchScale = (float)GD.RandRange(0.7, 1.3);
                gunAudio.Play();
                ammoBar.Call("Unload");
                if (_raycast.IsColliding())
                {
                    var body = _raycast.GetCollider();
                    if (body.HasMethod("Damage"))
                    {
                        body.Call("Damage");
                    }
                }
                ammoTimer.Start(0.2f);
                await ToSignal(ammoTimer, "timeout");

                ammoBar.Call("Reload");
                ammoTimer.Start(0.5f);
                await ToSignal(ammoTimer, "timeout");

                canShoot = true;
            }
        }


        if (Input.IsActionJustPressed("zoom"))
        {
            isZoomed = !isZoomed;
        }

        if (isZoomed)
        {
            _camera.Fov = Mathf.Lerp(_camera.Fov, zoomFov, delta * zoomSmooth);
        }
        else
        {
            _camera.Fov = Mathf.Lerp(_camera.Fov, normalFov, delta * zoomSmooth);
        }


        inputMovementVector = inputMovementVector.Normalized();

        _dir += -camXform.basis.z * inputMovementVector.y;
        _dir += camXform.basis.x * inputMovementVector.x;

        if (Input.IsActionJustPressed("ui_cancel"))
        {
            if (Input.GetMouseMode() == Input.MouseMode.Visible)
            {
                Input.SetMouseMode(Input.MouseMode.Captured);
            }
            else
            {
                Input.SetMouseMode(Input.MouseMode.Visible);
            }
        }
    }