// public override void _Ready() // { // // Called every time the node is added to the scene. // // Initialization here // } public override void _PhysicsProcess(float delta) { AnimatedSprite enemySprite = GetNode <AnimatedSprite>("EnemySprite"); AnimatedSprite reactionSprite = GetNode <AnimatedSprite>("ReactionSprite"); Node player = GetParent().GetNode("Player"); Area2D hitbox = GetNode <Area2D>("Hitbox"); Area2D aggro = GetNode <Area2D>("Aggro"); CollisionShape2D aggroRange = aggro.GetNode <CollisionShape2D>("AggroRange"); enemySprite.Play("walk"); // velocity.y += GRAV; but lets make him float if (patrolMode) { velocity.x = SPEED * direction * targetAquired; } velocity = MoveAndSlide(velocity, FLOOR); if (IsOnWall()) { direction *= -1; aggroRange.SetPosition(aggroRange.GetPosition() * (-1)); } //direction == -1 ? enemySprite.FlipH = true : enemySprite.FlipH = false; WEŹ MI WYTŁUMACZ CZEMU TO KRUWA NIE DZIAŁA if (direction == -1) { enemySprite.FlipH = true; aggroRange.SetRotationDegrees(270); } else { enemySprite.FlipH = false; aggroRange.SetRotationDegrees(90); } if (aggro.OverlapsBody(player)) { reactionSprite.Play("aggroON"); GD.Print("Player in aggro range."); targetAquired = 2; } else if (targetAquired == 2 && !aggro.OverlapsBody(player)) { reactionSprite.Play("aggroOFF"); GD.Print("Target lost."); targetAquired = 1; } if (hitbox.OverlapsBody(player)) { player.Set("hasFatallyCollided", true); } }
public override void _PhysicsProcess(float delta) { AnimatedSprite enemySprite = GetNode <AnimatedSprite>("EnemySprite"); AnimatedSprite reactionSprite = GetNode <AnimatedSprite>("ReactionSprite"); Node player = GetParent().GetNode("Player"); Area2D hitbox = GetNode <Area2D>("Hitbox"); Area2D aggro = GetNode <Area2D>("Aggro"); enemyPosition = enemySprite.GlobalPosition; CollisionShape2D aggroRange = aggro.GetNode <CollisionShape2D>("AggroRange"); enemySprite.Play("walk"); // velocity.y += GRAV; but lets make him float velocity.x = SPEED * directionx * targetAquired; velocity.y = SPEED * directiony * targetAquired; velocity = MoveAndSlide(velocity, FLOOR); if (IsOnWall() && !CheckLadder(enemyPosition)) //CheckLadder = true and IsOnWall() = true most likely cant ever happen { directionx *= -1; directiony = 0; movingHorizontally = true; aggroRange.SetPosition(aggroRange.GetPosition() * (-1)); } if (movingHorizontally && CheckLadder(enemyPosition) && !IsOnWall()) { ChangeDir("down", "left", "right", "up"); } else if (movingVertically && CheckLadderUnder(enemyPosition) && !CheckLadderAt(enemyPosition)) { ChangeDir("down", "left", "right"); } else if (IsOnFloor() && CheckLadderAt(enemyPosition)) { ChangeDir("up", "left", "right"); } if (directionx == -1) { enemySprite.FlipH = true; aggroRange.SetRotationDegrees(270); } else if (directionx == 1) { enemySprite.FlipH = false; aggroRange.SetRotationDegrees(90); } else if (directiony == -1) { enemySprite.FlipH = false; aggroRange.SetRotationDegrees(180); } else if (directiony == 1) { enemySprite.FlipH = false; aggroRange.SetRotationDegrees(0); } // NO AGGRO FOR NOW // if (aggro.OverlapsBody(player)) { // reactionSprite.Play("aggroON"); // GD.Print("Player in aggro range."); // targetAquired = 2; // } else if (targetAquired == 2 && !aggro.OverlapsBody(player)) { // reactionSprite.Play("aggroOFF"); // GD.Print("Target lost."); // targetAquired = 1; // } if (hitbox.OverlapsBody(player)) { player.Set("hasFatallyCollided", true); } }