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"); } } }
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 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) { 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 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; } }
//Called whenever the player inputs something public override void _Input(InputEvent @event) { if (@event is InputEventMouseMotion event_mouse_motion) { //Move camera according to mouse motion head.RotateY(Deg2Rad(-1 * event_mouse_motion.Relative.x * mouse_sens)); float dx_rot = event_mouse_motion.Relative.y * mouse_sens; if (cam_angle - dx_rot > -90 && cam_angle - dx_rot < 90) { cam.RotateX(Deg2Rad(-1 * dx_rot)); cam_angle -= dx_rot; } } if (@event.IsActionPressed("player_block_place") && raycast.IsColliding() && mat != null) { //Place blocks! int[] g_pos = Vector3ToInts(world_grid.WorldToMap(raycast.GetCollisionPoint() + TOLERANCE * Heading())); if (world_grid.GetCellItem(g_pos[0], g_pos[1], g_pos[2]) == -1) { world_grid.SetCellItem(g_pos[0], g_pos[1], g_pos[2], mat.ml_idx); } } if (@event.IsActionReleased("player_pause")) { cap_mouse = !cap_mouse; SwitchMouseMode(); } }
void CalculateMoveToFloor(float delta) { if (IsOnFloor()) { hasFloorContact = true; forcedWalk = false; alowJumpInput = true; Vector3 floorNormal = floorChecker.GetCollisionNormal(); float floorAngle = Mathf.Rad2Deg(Mathf.Acos(floorNormal.Dot(Vector3.Up))); if (floorAngle > maxSlopeAngle) { forcedWalk = true; airJumpsLeft = 0; Fall(delta); } } else { if (!floorChecker.IsColliding()) { hasFloorContact = false; Fall(delta); } } if (hasFloorContact && !IsOnFloor()) { MoveAndCollide(Vector3.Down); } }
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()); }
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) { //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 void HandleCrouchInput(float Delta) { float OldCrouchPercentage = CrouchPercent; if (Input.IsActionPressed("Sneak")) { CrouchPercent = Clamp(CrouchPercent + (Delta / MaxCrouchTime), 0, 1); } else if (!CeilingCast.IsColliding()) { CrouchPercent = Clamp(CrouchPercent - (Delta / MaxCrouchTime), 0, 1); } float Shrink = (HullHeight - CrouchedHullHeight) * CrouchPercent; var Shape = ((CapsuleShape)Hull.Shape); float OriginalHeight = Shape.Height; Shape.Height = HullHeight - Shrink; Hull.Translation = new Vector3(0, 0 + (Shrink / 2f), 0); Translation = new Vector3( Translation.x, Translation.y + (Shape.Height - OriginalHeight), Translation.z ); CamJoint.Translation = new Vector3(0, 1.75f - CrouchPercent, 0); }
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) { 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(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 _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; } }
// Handle player crouch private void crouch(float delta) { if (!headRay.IsColliding()) { CollisionShape shape = (CollisionShape)GetNode("body"); CylinderShape capsule = ((CylinderShape)shape.Shape); // Height of collision shape float newCollisionHeight = Mathf.Lerp(capsule.Height, 2 - (input["crouch"] * 1.5f), crouchSpeed * delta); capsule.Height = newCollisionHeight; } }
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 void GroundMove(float delta, PlayerCmd pCmd) { Vector3 wishDir = new Vector3(); float scale = CmdScale(pCmd); wishDir += pCmd.aim.x * pCmd.move_right; wishDir -= pCmd.aim.z * pCmd.move_forward; wishDir = wishDir.Normalized(); _moveDirectionNorm = wishDir; float wishSpeed = wishDir.Length(); wishSpeed *= MoveSpeed; Accelerate(wishDir, wishSpeed, _runAcceleration, delta); if (_climbLadder) { if (pCmd.move_forward != 0f) { _playerVelocity.y = _moveSpeed * (pCmd.cam_angle / 90) * pCmd.move_forward; } else { _playerVelocity.y = 0; } if (pCmd.move_right == 0f) { _playerVelocity.x = 0; _playerVelocity.z = 0; } } // walk up stairs if (wishSpeed > 0 && _stairCatcher.IsColliding()) { Vector3 col = _stairCatcher.GetCollisionNormal(); float ang = Mathf.Rad2Deg(Mathf.Acos(col.Dot(_game.World.Up))); if (ang < _maxStairAngle) { _playerVelocity.y = _stairJumpHeight; } } if (_wishJump && IsOnFloor()) { // FIXME - if we add jump speed velocity we enable trimping right? _playerVelocity.y = _jumpSpeed; _jumpSound.Play(); } }
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); } } } } ); }
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(); } }
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(); } } }
// // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(float delta) { var upDir = new Vector3(1, 0, 0); targetPos = GetNode <RigidBody>("/root/World/Target"); ktargetPos = GetNode <KinematicBody>("/root/World/KTarget"); //LookAt(ktargetPosition.GlobalTransform.origin,upDir); //LookAt(targetPos.GlobalTransform.origin,upDir); //ray.LookAt(targetPos.GlobalTransform.origin,upDir); //GD.Print(delta); if (ray.IsColliding()) { ShootAnim(delta); } }
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 CheckForExits() { if (roofRay.IsColliding()) { //Set the open flag on the wall making contact with the previous room roofOpen = true; //Delete the wall to open it up to the adjacent rooms exit roofWall.QueueFree(); } if (floorRay.IsColliding()) { //Set the open flag on the wall making contact with the previous room floorOpen = true; //Delete the wall to open it up to the adjacent rooms exit floorWall.QueueFree(); } if (frontRay.IsColliding()) { //Set the open flag on the wall making contact with the previous room frontOpen = true; //Delete the wall to open it up to the adjacent rooms exit frontWall.QueueFree(); } if (backRay.IsColliding()) { //Set the open flag on the wall making contact with the previous room backOpen = true; //Delete the wall to open it up to the adjacent rooms exit backWall.QueueFree(); } if (leftRay.IsColliding()) { //Set the open flag on the wall making contact with the previous room leftOpen = true; //Delete the wall to open it up to the adjacent rooms exit leftWall.QueueFree(); } if (rightRay.IsColliding()) { //Set the open flag on the wall making contact with the previous room rightOpen = true; //Delete the wall to open it up to the adjacent rooms exit rightWall.QueueFree(); } }
public override void _PhysicsProcess(float delta) { Vector3 keys_vector = Vector3.Zero; if (floor_check.IsColliding()) { if (Array.Exists <int>(keys_in, n => n == 1)) { if (Input.IsKeyPressed((int)KeyList.Shift)) { move_vector = move_vector * .99f; } else { move_vector = move_vector * .95f; } } else { move_vector = move_vector * .75f; } if (Input.GetMouseMode() == Input.MouseMode.Captured) { keys_vector = new Vector3(keys_in[3] - keys_in[1], 0, keys_in[2] - keys_in[0]); keys_vector = keys_vector.Rotated(Vector3.Up, Rotation.y); move_vector += keys_vector * delta; move_vector += Vector3.Up * jump_power * (Input.IsKeyPressed((int)KeyList.Space) ? 1 : 0); } } move_vector += gravity * delta; var output = MoveAndCollide((move_vector.Normalized() * move_vector.Length()) * move_scaler); if (output is KinematicCollision kc) { move_vector += -kc.Normal * kc.Normal.Dot(move_vector); } }
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; } }