public void HandleFootsteps(float Delta) { float Decrement = Delta; float Muffle = 16; if (Round(Momentum.Flattened().Length()) > BaseSpeed) { Decrement *= SprintingFootstepAcceleration; Muffle = 0; } FootstepCountdown -= Decrement; if (OnFloor && Mode != MovementMode.SNEAKING && (BackwardForwardDirection != 0 || RightLeftDirection != 0)) { if (FootstepCountdown <= 0) { FootstepCountdown = FootstepBaseTime; int Index = -1; var Catagory = (SfxCatagory)(-1); if (FloorCast.GetCollider() is Node Floor) { if (Floor.IsInGroup("concrete")) { Index = ConcreteChooser.Choose(); Catagory = SfxCatagory.CONCRETE_FOOTSTEPS; } else if (Floor.IsInGroup("leaves")) { Index = LeavesChooser.Choose(); Catagory = SfxCatagory.LEAVES_FOOTSTEPS; } else if (Floor.IsInGroup("metal")) { Index = MetalChooser.Choose(); Catagory = SfxCatagory.METAL_FOOTSTEPS; } else if (Floor.IsInGroup("marble")) { Index = MarbleChooser.Choose(); Catagory = SfxCatagory.MARBLE_FOOTSTEPS; } else { Index = ConcreteChooser.Choose(); Catagory = SfxCatagory.CONCRETE_FOOTSTEPS; } } if (Index != -1) { ActualAssert(Catagory != (SfxCatagory)(-1)); Sfx.PlaySfx(Catagory, Index, GlobalTransform.origin, Muffle); } } } }
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(); } }
public override void _PhysicsProcess(float delta) { base._PhysicsProcess(delta); ProcessInput(delta); ProcessMovement(delta); var rayInteractable = CameraRayCast.GetCollider(); if (CurrentInteractable != rayInteractable) { CurrentInteractable = rayInteractable; EmitSignal(nameof(InteractableUpdated), CurrentInteractable); } }
private void InputSpawn() { RayCast frontRayCast = _moveWrapper.GetChild <RayCast>(1); RayCast frontGroundRayCast = _moveWrapper.GetChild <RayCast>(2); var frontGround = (Node)frontGroundRayCast.GetCollider(); string name = NameGetter.FromCollision(frontGround); //check the player requested a spawn on an empty tile above ground if (frontGround != null) { if (Input.IsActionJustPressed("ui_select") && !frontRayCast.IsColliding() && (name == "GridMap" || name == "pot")) { //spawn a flower in front of the player Spatial flowerInstance = (Spatial)_flowerPlatform.Instance(); flowerInstance.Translation = Translation + _moveWrapper.Translation + moveWrapper.SPEED * FacingVec(); GetParent().AddChild(flowerInstance); if (name == "pot") { ((moveWrapper)frontGround).planted = true; } } } }
public override void _PhysicsProcess(float Delta) { Items.Instance Item = Game.PossessedPlayer.Inventory[Game.PossessedPlayer.InventorySlot]; if (Item != null && Item.Type != CurrentMeshType) //null means no item in slot { GhostMesh.Mesh = Meshes[Item.Type]; CurrentMeshType = Item.Type; } GhostMesh.Translation = OldPositions[0]; GhostMesh.RotationDegrees = OldRotations[0]; GhostMesh.Visible = OldVisible[0]; Player Plr = Game.PossessedPlayer; OldVisible.RemoveAt(0); OldVisible.Add(false); if (Plr.Inventory[Plr.InventorySlot] != null) { RayCast BuildRayCast = Plr.GetNode("SteelCamera/RayCast") as RayCast; if (BuildRayCast.IsColliding()) { Structure Hit = BuildRayCast.GetCollider() as Structure; if (Hit != null) { System.Nullable <Vector3> GhostPosition = BuildPositions.Calculate(Hit, Plr.Inventory[Plr.InventorySlot].Type); if (GhostPosition != null) { Vector3 GhostRotation = BuildRotations.Calculate(Hit, Plr.Inventory[Plr.InventorySlot].Type); Translation = (Vector3)GhostPosition; RotationDegrees = GhostRotation; OldVisible[1] = true; } } } } if (OldVisible[1] == false) { OldVisible[0] = false; GhostMesh.Visible = false; } OldCanBuild.RemoveAt(0); if (GetOverlappingBodies().Count > 0) { GhostMesh.MaterialOverride = RedMat; OldCanBuild.Add(false); } else { GhostMesh.MaterialOverride = GreenMat; OldCanBuild.Add(true); } CanBuild = OldCanBuild[0]; OldPositions.RemoveAt(0); OldPositions.Add(Translation); OldRotations.RemoveAt(0); OldRotations.Add(RotationDegrees); }
public void PrimaryFire(double Sens) { if (Sens > 0d && !IsFiring) { IsFiring = true; if (Inventory[InventorySlot] != null) { //Assume for now that all primary fire opertations are to build RayCast BuildRayCast = GetNode("SteelCamera/RayCast") as RayCast; if (BuildRayCast.IsColliding()) { Structure Hit = BuildRayCast.GetCollider() as Structure; if (Hit != null) { Building.Request(Hit, Inventory[InventorySlot].Type, 1); //ID 1 for now so all client own all non-default structures } } } } if (Sens <= 0d && IsFiring) { IsFiring = false; } }
protected virtual void HandleProjectile(Spatial projectile) { IProjectile iProjectile = projectiles[projectile]; if (iProjectile.IsAlive()) { AttackData attackData = iProjectile.GetAttackData(); Vector3 b = -projectile.Transform.basis.GetAxis(2); projectile.Translation += b * attackData.deltaTime * 5; rayCast = projectile.GetNodeInChildrenByType <RayCast>(); if (rayCast != null && rayCast.IsColliding()) { if (!(attackData.target is IDamageReceiver)) { Node collider = rayCast.GetCollider() as Node; if (collider is IDamageReceiver) { attackData.target = collider; } } base.ProcessAttack(attackData); } } else { iProjectile.Deactivate(); projectiles.Remove(projectile); pooledProjectiles.Enqueue(projectile); } }
public void Fire() { Weapon.Attack(); if (Weapon.ProjectileType != Projectile.Type.None) { //put projectile in game var scene2 = (PackedScene)GD.Load(Resources.ScenePath + Weapon.ProjectileType.ToString() + ".tscn"); var sceneInstance2 = (Projectile)scene2.Instance(); var scale = sceneInstance2.Scale; Globals.Instance.CurrentLevel.GetNode("Projectiles").AddChild(sceneInstance2); var offset = Globals.GetRotationFrom(Resources.ProjectileOffset, BulletRay.GlobalTransform.basis.GetEuler()); sceneInstance2.Transform = new Transform(BulletRay.GlobalTransform.basis, BulletRay.GlobalTransform.origin + offset); // Vector3 forceSource = BulletRay.GlobalTransform.basis.GetEuler(); var bowPosition = new Vector3(sceneInstance2.GlobalTransform.origin) { y = 0 }; var hitPosition = Globals.GetRotationFrom(BulletRay.CastTo, BulletRay.GlobalTransform.basis.GetEuler()); if (BulletRay.IsColliding()) { hitPosition = new Vector3(BulletRay.GetCollisionPoint()) { y = 0 } } ; forceSource.y = Mathf.Atan2(-(bowPosition.x - hitPosition.x), -(bowPosition.z - hitPosition.z)); //apply force to projectile var force = Globals.GetRotationFrom(Resources.ProjectileImpulse, forceSource); sceneInstance2.ApplyCentralImpulse(force); sceneInstance2.Scale = scale * 10; sceneInstance2.Damage = Weapon.Damage; sceneInstance2.Firer = this; GD.Print(BulletRay.GetCollisionPoint().DistanceTo(GlobalTransform.origin)); if (BulletRay.GetCollisionPoint().DistanceTo(GlobalTransform.origin) <= Resources.TooCloseDistance) { sceneInstance2.IsTooClose = true; } return; } var other = (Spatial)BulletRay.GetCollider(); if (other == null) { return; } if (other.GetParent().GetParent().GetParent() is Person person) { person.TakeDamage(Weapon.Damage); } //TODO Add other colliders var pos = BulletRay.GetCollisionPoint(); //TODO blood or something (Particals) }
public override void _PhysicsProcess(float delta) { if (dead) { return; } if (player == null) { return; } var vecToPlayer = player.Translation - Translation; vecToPlayer = vecToPlayer.Normalized(); // monster "attack" is just when it's within MELEE_RANGE of player // when this raycast collides the attack is hitting the player rayCast.CastTo = vecToPlayer * MELEE_RANGE; // move towards the player MoveAndCollide(vecToPlayer * MOVE_SPEED * delta); if (rayCast.IsColliding()) { var coll = rayCast.GetCollider(); if (coll != null && coll is Player) { coll.Call("Kill"); } } }
public override void _PhysicsProcess(float delta) { //Add crouching logic if (IsCrouching) { Vector3 position = GlobalTransform.origin; _cam.Translation = new Vector3(0f, -.5f, 0f); Speed = MaxSpeed / 2f; } else { Vector3 position = GlobalTransform.origin; _cam.Translation = new Vector3(0f, 0f, 0f); Speed = MaxSpeed; } Velocity = MoveAndSlide(Velocity); //Make sure y pos is 2.5 Vector3 pos = GlobalTransform.origin; GlobalTransform = new Transform(GlobalTransform.basis, new Vector3(pos.x, 2.5f, pos.z)); if (_interactRayCast.IsColliding()) { Spatial collider = (Spatial)_interactRayCast.GetCollider(); if (collider.IsInGroup("Items")) { //add item pickup logic } } }
public override void _PhysicsProcess(float delta) { //implement fsm //pathfinding logic _points = new List <Vector3>(_nav.GetSimplePath(GlobalTransform.origin, _targetPlayer.GlobalTransform.origin)); if (_points.Count > 0) { if (RoundVector(GlobalTransform.origin).x == RoundVector(_points[0]).x&& RoundVector(GlobalTransform.origin).z == RoundVector(_points[0]).z) { _points.RemoveAt(0); } Velocity = Translation.DirectionTo(_points[0]) * Speed; Velocity = MoveAndSlide(Velocity); } //Collision Logic _rayCast.CastTo = _rayCast.ToLocal(_targetPlayer.GlobalTransform.origin); if (_rayCast.IsColliding()) { Spatial collider = (Spatial)_rayCast.GetCollider(); if (collider is Player && GlobalTransform.origin.DistanceTo(collider.GlobalTransform.origin) <= 3f) { // GD.Print("hit player"); GetTree().ChangeScene("res://GameOver/GameOver.tscn"); } } }
public override void _Process(float delta) { if (footStepTimer <= 0) { if ((Vector3)player.Get("direction") != Vector3.Zero && feet.IsColliding()) { // Get collided body group name Godot.Collections.Array collidedGroups = ((Node)feet.GetCollider()).GetGroups(); foreach (String group in collidedGroups) { if (footStepList.ContainsKey(group)) { Node footStepNode = footStepList[group]; if (footStepNode.GetChildCount() > 0) { // Play audio int randomIndex = (int)GD.RandRange(0, footStepNode.GetChildCount() - 1); AudioStreamPlayer3D audio = (AudioStreamPlayer3D)footStepNode.GetChild(randomIndex); audio.Play(); // Sync player speed with audio loop footStepTimer = (1 - (0.06f * (float)player.Get("normalSpeed"))); break; } } } } } else { footStepTimer -= delta; } }
public override void _Process(float delta) { Node target = (Node)raycast.GetCollider(); Player.Instance.lookingAt = target; if (Input.IsActionJustPressed("ui_click")) { if (target is IInteractable) { interactionTarget = (IInteractable)target; interactionTarget.Interact(Interaction.PRESS); } } if (Input.IsActionJustReleased("ui_click")) { if (interactionTarget != null) { interactionTarget.Interact(Interaction.RELEASE); } } if (Input.IsActionJustPressed("fps_zoom")) { zoomLevel += 1; if (zoomLevel > 1) { zoomLevel = 0; } this.Fov = 70 - 30 * zoomLevel; } }
public void PrimaryFire(float Sens) { if (Sens > 0 && !IsPrimaryFiring) { IsPrimaryFiring = true; if (Inventory[InventorySlot] != null) { //Assume for now that all primary fire opertations are to build RayCast BuildRayCast = GetNode("SteelCamera/RayCast") as RayCast; if (BuildRayCast.IsColliding()) { Structure Hit = BuildRayCast.GetCollider() as Structure; if (Hit != null && GhostInstance.CanBuild) { Vector3?PlacePosition = BuildPositions.Calculate(Hit, GhostInstance.CurrentMeshType); if (PlacePosition != null && Game.Mode.ShouldPlaceStructure(GhostInstance.CurrentMeshType, PlacePosition.Value, BuildRotations.Calculate(Hit, GhostInstance.CurrentMeshType))) { World.PlaceOn(Hit, GhostInstance.CurrentMeshType, 1); //ID 1 for now so all client own all non-default structures } } } } } if (Sens <= 0 && IsPrimaryFiring) { IsPrimaryFiring = false; } }
public override void _PhysicsProcess(float delta) { var moveVec = new Vector3(); if (Input.IsActionPressed("move_forwards")) { moveVec.z -= 1; } if (Input.IsActionPressed("move_backwards")) { moveVec.z += 1; } if (Input.IsActionPressed("move_left")) { moveVec.x -= 1; } if (Input.IsActionPressed("move_right")) { moveVec.x += 1; } moveVec = moveVec.Normalized(); // prevents faster diagonal movement moveVec = moveVec.Rotated(new Vector3(0.0f, 1.0f, 0.0f), Rotation.y); MoveAndCollide(moveVec * MOVE_SPEED * delta); if (Input.IsActionPressed("shoot") && !animPlayer.IsPlaying()) { animPlayer.Play("shoot"); // shoot the bullet as a hitscan ray var coll = rayCast.GetCollider(); if (rayCast.IsColliding() && coll.HasMethod("Kill")) { coll.Call("Kill"); } } }
public override State tick(Node entity) { if (ray != null && ray.GetCollider() != null) { return(State.Failure); } return(State.Success); }
void HandleRaycast() { if (raycast.IsColliding()) { interactable = (InteractableObject)((Area)raycast.GetCollider()).GetParent(); interactable.SetHighlight(true); } else if (interactable != null) { interactable.SetHighlight(false); interactable = null; } }
public void CheckCollision() { if (rayCast.IsColliding()) { GD.Print("colliding"); Node collider = (Node)rayCast.GetCollider(); if (collider.IsInGroup("Enemies")) { collider.QueueFree(); GD.Print($"Killed ", collider.Name); } } }
public static void SecondaryFire(float Sens) { Game.PossessedPlayer.MatchSome( (Plr) => { if (Sens > 0 && !Plr.IsSecondaryFiring) { Plr.IsSecondaryFiring = true; Items.Instance CurrentItem = Plr.Inventory[Plr.InventorySlot]; if (CurrentItem == null || !Items.IdInfos[CurrentItem.Id].CanAds) { if (Plr.CurrentCooldown >= Plr.CurrentMaxCooldown) { RayCast BuildRayCast = Plr.GetNode <RayCast>("SteelCamera/RayCast"); if (BuildRayCast.IsColliding()) { if (BuildRayCast.GetCollider() is Tile Hit) { Hit.NetRemove(); Plr.SetCooldown(0, Player.BuildingCooldown, true); } } } } else if (CurrentItem != null && Items.IdInfos[CurrentItem.Id].CanAds) { Plr.Ads = true; Plr.IsFlySprinting = false; } } if (Sens <= 0 && Plr.IsSecondaryFiring) { Plr.IsSecondaryFiring = false; Items.Instance CurrentItem = Plr.Inventory[Plr.InventorySlot]; if (CurrentItem != null && Items.IdInfos[CurrentItem.Id].CanAds) { Plr.Ads = false; if (Plr.FlySprintSens > 0) { FlySprint(Plr.FlySprintSens); } } } } ); }
private void ProcessInteraction(float delta) { if (_raycast.GetCollider() is InteractiveItem collider) { if (Input.IsActionJustPressed("interract")) { collider.Interact(this); } _interactIcon.Show(); } else { _interactIcon.Hide(); } }
private void Fire() { GD.Print("Fired Weapon"); shootCD.Start(); current_ammo -= 1; if (raycast.IsColliding()) { Godot.Object collider = raycast.GetCollider(); if (collider is Node collider_node && collider_node.IsInGroup("targets")) { GD.Print(String.Format("Killed {0}", collider_node.Name)); collider_node.QueueFree(); } } }
public void SecondaryFire(float Sens) { if (Sens > 0 && !IsSecondaryFiring) { IsSecondaryFiring = true; Items.Instance CurrentItem = Inventory[InventorySlot]; if (CurrentItem == null || !Items.IdInfos[CurrentItem.Id].CanAds) { if (CurrentCooldown >= CurrentMaxCooldown) { RayCast BuildRayCast = GetNode("SteelCamera/RayCast") as RayCast; if (BuildRayCast.IsColliding()) { Tile Hit = BuildRayCast.GetCollider() as Tile; if (Hit != null && Game.Mode.ShouldRemoveTile(Hit.Type, Hit.Translation, Hit.RotationDegrees, Hit.OwnerId)) { Hit.NetRemove(); SetCooldown(0, BuildingCooldown, true); } } } } else if (CurrentItem != null && Items.IdInfos[CurrentItem.Id].CanAds) { Ads = true; IsSprinting = false; } } if (Sens <= 0 && IsSecondaryFiring) { IsSecondaryFiring = false; Items.Instance CurrentItem = Inventory[InventorySlot]; if (CurrentItem != null && Items.IdInfos[CurrentItem.Id].CanAds) { Ads = false; if (SprintSens > 0) { Sprint(SprintSens); } } } }
public void dispara() { try { Jugador jugador = (Jugador)GetNode("Jugador"); // efecto del disparo jugador.disparaArma(); Spatial Cabeza = (Spatial)jugador.GetNode("Cabeza"); Camera objcamera = (Camera)Cabeza.GetNode("Camera"); RayCast ray = (RayCast)objcamera.GetNode("RayCast"); if (ray.Enabled && ray.IsColliding()) { Godot.Object objetivo = (Godot.Object)ray.GetCollider(); Vector3 vectorimpacto = ray.GetCollisionPoint(); // si el impacto lo recibe un objeto preparado para recibir balas if (objetivo.HasMethod("recibeBala")) { // calculamos la direccion del impacto Vector3 inicio = ray.Translation; Vector3 vectordir = vectorimpacto - inicio; objetivo.Call("recibeBala", vectordir); } // pintamos el impacto de la bala // debug con cajas en vez de impacto poneCajaEscenario(vectorimpacto); /* * PackedScene objeto = (PackedScene)ResourceLoader.Load("res://objetos/mini/ImpactoBalaPared.tscn"); * // objetos.mini.ImpactoBalaPared efecto = (objetos.mini.ImpactoBalaPared)objeto.Instance(); * ImpactoBalaPared efecto = (ImpactoBalaPared)objeto.Instance(); * AddChild(efecto); * efecto.haceEfecto(vectorimpacto); */ } } catch (Exception ex) { } }
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 Interact() { var collider = raycast.GetCollider(); interactLabel.Visible = false; if (collider != null) { if (collider.HasMethod("Interact")) { interactLabel.Visible = true; if (Input.IsActionJustPressed("Interact")) { collider.Call("Interact"); } } } }
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; } }
public void PrimaryFire(float Sens) { if (Sens > 0 && !IsPrimaryFiring && CurrentCooldown >= CurrentMaxCooldown) { IsPrimaryFiring = true; if (Inventory[InventorySlot] != null) { if (Items.IdInfos[Inventory[InventorySlot].Id].PositionDelegate != null) { RayCast BuildRayCast = GetNode("SteelCamera/RayCast") as RayCast; if (BuildRayCast.IsColliding()) { Tile Base = BuildRayCast.GetCollider() as Tile; if (Base != null && GhostInstance.CanBuild) { Vector3?PlacePosition = Items.TryCalculateBuildPosition(GhostInstance.CurrentMeshType, Base, RotationDegrees.y, BuildRotation, BuildRayCast.GetCollisionPoint()); if (PlacePosition != null && Game.Mode.ShouldPlaceTile(GhostInstance.CurrentMeshType, PlacePosition.Value, Items.CalculateBuildRotation(GhostInstance.CurrentMeshType, Base, RotationDegrees.y, BuildRotation, BuildRayCast.GetCollisionPoint()))) { World.PlaceOn(GhostInstance.CurrentMeshType, Base, RotationDegrees.y, BuildRotation, BuildRayCast.GetCollisionPoint(), 1); //ID 1 for now so all client own all non-default structures SetCooldown(0, BuildingCooldown, true); } } } } if (Items.IdInfos[Inventory[InventorySlot].Id].UseDelegate != null) { Items.UseItem(Inventory[InventorySlot], this); } } } if (Sens <= 0 && IsPrimaryFiring) { IsPrimaryFiring = false; } }
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); }
void CheckFiring() { if (!IsFiring || IsReloading || CurAmmo <= 0 || NextThink > 0.0) { return; } Vector3 from = CameraNode.GlobalTransform.origin; Vector3 to = from + ((-CameraNode.GlobalTransform.basis[2]).normalized() * 100.0f); ViewModel.SetWpnAnimation("shoot", true); CurAmmo = Mathf.min(Mathf.max(CurAmmo - 1, 0), MaxAmmo); NextThink = 1.0f / 10.0f; if (FiringRaycast.IsColliding()) { Godot.Object collider = FiringRaycast.GetCollider(); GD.print("Collider: ", collider.GetClass()); } }