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; } }
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; } }
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; } }