TileMapLayer collisions with area2d sucessfull
This commit is contained in:
@@ -148,6 +148,7 @@ texture = ExtResource("1_q0x10")
|
|||||||
|
|
||||||
[sub_resource type="TileSet" id="TileSet_q0ben"]
|
[sub_resource type="TileSet" id="TileSet_q0ben"]
|
||||||
physics_layer_0/collision_layer = 1
|
physics_layer_0/collision_layer = 1
|
||||||
|
physics_layer_0/collision_mask = 0
|
||||||
sources/0 = SubResource("TileSetAtlasSource_e35rp")
|
sources/0 = SubResource("TileSetAtlasSource_e35rp")
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_owkni"]
|
[sub_resource type="Animation" id="Animation_owkni"]
|
||||||
@@ -227,7 +228,7 @@ _data = {
|
|||||||
[node name="Level1" type="Node2D"]
|
[node name="Level1" type="Node2D"]
|
||||||
|
|
||||||
[node name="PlayArea" type="TileMapLayer" parent="."]
|
[node name="PlayArea" type="TileMapLayer" parent="."]
|
||||||
tile_map_data = PackedByteArray("AAD//wAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAACAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAGAAAAAAAAAAAAAAAHAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAJAAAAAAAAAAAAAAAKAAAAAAAAAAAAAAAOAAAAAAAAAAAAAAAPAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAD//wEAAAAAAAEAAAAAAAEAAAAAAAEAAAABAAEAAAAAAAEAAAACAAEAAAAAAAEAAAADAAEAAAAAAAEAAAAEAAEAAAAAAAEAAAAFAAEAAAAAAAEAAAAGAAEAAAAAAAEAAAAHAAEAAAAAAAEAAAAIAAEAAAAAAAEAAAAJAAEAAAAAAAEAAAAKAAEAAAAAAAEAAAALAAEAAAAAAAAAAAAMAAEAAAAAAAAAAAANAAEAAAAAAAAAAAAOAAEAAAAAAAEAAAAPAAEAAAAAAAEAAAAQAAEAAAAAAAEAAAARAAEAAAAAAAAAAAA=")
|
tile_map_data = PackedByteArray("AAD//wAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAACAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAGAAAAAAAAAAAAAAAHAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAJAAAAAAAAAAAAAAAKAAAAAAAAAAAAAAD//wEAAAAAAAEAAAAAAAEAAAAAAAEAAAABAAEAAAAAAAEAAAACAAEAAAAAAAEAAAADAAEAAAAAAAEAAAAEAAEAAAAAAAEAAAAFAAEAAAAAAAEAAAAGAAEAAAAAAAEAAAAHAAEAAAAAAAEAAAAIAAEAAAAAAAEAAAAJAAEAAAAAAAEAAAAKAAEAAAAAAAEAAAALAAEAAAAAAAAAAAAMAAEAAAAAAAAAAAANAAEAAAAAAAAAAAAOAAEAAAAAAAAAAAAPAAEAAAAAAAAAAAAQAAEAAAAAAAAAAAARAAEAAAAAAAAAAAASAAEAAAAAAAEAAAASAAAAAAAAAAAAAAATAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAUAAEAAAAAAAEAAAATAAEAAAAAAAEAAAA=")
|
||||||
tile_set = SubResource("TileSet_q0ben")
|
tile_set = SubResource("TileSet_q0ben")
|
||||||
|
|
||||||
[node name="Background" type="TileMapLayer" parent="."]
|
[node name="Background" type="TileMapLayer" parent="."]
|
||||||
@@ -239,7 +240,7 @@ tile_set = SubResource("TileSet_q0ben")
|
|||||||
[node name="Enemies" type="Node" parent="."]
|
[node name="Enemies" type="Node" parent="."]
|
||||||
|
|
||||||
[node name="IQEnemy" parent="Enemies" instance=ExtResource("8_s63xy")]
|
[node name="IQEnemy" parent="Enemies" instance=ExtResource("8_s63xy")]
|
||||||
position = Vector2(248, -10)
|
position = Vector2(221, -26)
|
||||||
|
|
||||||
[node name="StaticThreats" type="Node" parent="."]
|
[node name="StaticThreats" type="Node" parent="."]
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ public partial class IQEnemy : CharacterBody2D
|
|||||||
float PreviousYVelocity;
|
float PreviousYVelocity;
|
||||||
bool GroundDetected;
|
bool GroundDetected;
|
||||||
bool LedgeDetected;
|
bool LedgeDetected;
|
||||||
|
bool WallDetected;
|
||||||
|
String FacingDirection;
|
||||||
|
|
||||||
// Enemy Abilities
|
// Enemy Abilities
|
||||||
bool AbilityJump = false;
|
bool AbilityJump = false;
|
||||||
@@ -45,22 +47,26 @@ public partial class IQEnemy : CharacterBody2D
|
|||||||
if (HasMeta("RegenerationInterval")) RegenerationInterval = (float)GetMeta("RegenerationInterval");
|
if (HasMeta("RegenerationInterval")) RegenerationInterval = (float)GetMeta("RegenerationInterval");
|
||||||
else RegenerationInterval = 1.0f;
|
else RegenerationInterval = 1.0f;
|
||||||
if (HasMeta("WalkSpeed")) WalkSpeed = (float)GetMeta("WalkSpeed");
|
if (HasMeta("WalkSpeed")) WalkSpeed = (float)GetMeta("WalkSpeed");
|
||||||
else WalkSpeed = 10.0f;
|
else WalkSpeed = 20.0f;
|
||||||
if (HasMeta("JumpHeight")) JumpHeight = (float)GetMeta("JumpHeight");
|
if (HasMeta("JumpHeight")) JumpHeight = (float)GetMeta("JumpHeight");
|
||||||
else JumpHeight = 10.0f;
|
else JumpHeight = 20.0f;
|
||||||
|
|
||||||
// Read and set stats
|
// Read and set stats
|
||||||
if (HasMeta("MaxHP")) MaxHP = (float)GetMeta("MaxHP");
|
if (HasMeta("MaxHP")) MaxHP = (float)GetMeta("MaxHP");
|
||||||
|
|
||||||
// Set up ground detection
|
// Set up collision detection
|
||||||
GetNode<Area2D>("GroundDetector").AreaEntered += OnGroundEntered;
|
GetNode<Area2D>("GroundDetector").BodyEntered += OnGroundEntered; // Ground
|
||||||
GetNode<Area2D>("GroundDetector").AreaExited += OnGroundExited;
|
GetNode<Area2D>("GroundDetector").BodyExited += OnGroundExited;
|
||||||
|
GetNode<Area2D>("LedgeDetector").BodyEntered += OnLedgeEntered; // Ledge
|
||||||
|
GetNode<Area2D>("LedgeDetector").BodyExited += OnLedgeExited;
|
||||||
|
GetNode<Area2D>("WallDetector").BodyEntered += OnWallEntered; // Wall
|
||||||
|
GetNode<Area2D>("WallDetector").BodyExited += OnWallExited;
|
||||||
|
|
||||||
GetNode<Area2D>("LedgeDetector").AreaEntered += OnLedgeEntered;
|
GroundDetected = false;
|
||||||
GetNode<Area2D>("LedgeDetector").AreaExited += OnLedgeExited;
|
LedgeDetected = false;
|
||||||
|
WallDetected = false;
|
||||||
|
|
||||||
GroundDetected = true;
|
FacingDirection = "RIGHT";
|
||||||
LedgeDetected = true;
|
|
||||||
|
|
||||||
// Apply IQ based permenant modifiers
|
// Apply IQ based permenant modifiers
|
||||||
IQ = (int)GetMeta("IQ"); // Read IQ
|
IQ = (int)GetMeta("IQ"); // Read IQ
|
||||||
@@ -86,19 +92,27 @@ public partial class IQEnemy : CharacterBody2D
|
|||||||
|
|
||||||
// Movement
|
// Movement
|
||||||
// Add gravity.
|
// Add gravity.
|
||||||
if (GroundDetected == false){Velocity = new Vector2(Velocity[0],-1);}
|
if (GroundDetected == false){Velocity = new Vector2(Velocity[0],100);}
|
||||||
|
|
||||||
if (IQ <= 20){ // Goomba ahh diddy blud
|
if (IQ <= 20){ // Goomba ahh diddy blud
|
||||||
if (GroundDetected && LedgeDetected == false) {Flip("ANY");}
|
if (GroundDetected && LedgeDetected == false){Flip();}
|
||||||
if (Scale[0] > 0){Velocity = new Vector2(WalkSpeed, Velocity[1]);} // Facing right
|
if (WallDetected){Flip();}
|
||||||
if (Scale[0] < 0){Velocity = new Vector2(-1 * WalkSpeed, Velocity[1]);} // Facing left
|
// Walk
|
||||||
|
if (GroundDetected){Velocity = new Vector2(WalkSpeed * Scale[0], Velocity[1]);}
|
||||||
}
|
}
|
||||||
MoveAndSlide();
|
MoveAndSlide(); // Updates physics applied this frame
|
||||||
}
|
}
|
||||||
|
|
||||||
void Flip(string facing){
|
void Flip(){
|
||||||
if (facing == "ANY") Scale = new Vector2(Scale[0] * -1,1);
|
if (FacingDirection == "RIGHT"){
|
||||||
if (facing == "RIGHT") Scale = new Vector2(1,1);
|
Scale = new Vector2(-1,1);
|
||||||
if (facing =="LEFT") Scale = new Vector2(-1,1);
|
FacingDirection = "LEFT";
|
||||||
|
}
|
||||||
|
else if (FacingDirection == "LEFT")
|
||||||
|
{
|
||||||
|
Scale = new Vector2(1,1);
|
||||||
|
FacingDirection = "RIGHT";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Regenerate(float ammount){
|
public void Regenerate(float ammount){
|
||||||
@@ -116,9 +130,12 @@ public partial class IQEnemy : CharacterBody2D
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ground Detection
|
// Ground Detection
|
||||||
public void OnGroundEntered(Area2D area){if (area.CollisionLayer == 0) GroundDetected = true;}
|
public void OnGroundEntered(Node2D body){if (body is TileMapLayer tileLayer) GroundDetected = true;}
|
||||||
public void OnGroundExited(Area2D area){if (area.CollisionLayer == 0) GroundDetected = false;}
|
public void OnGroundExited(Node2D body){if (body is TileMapLayer tileLayer) GroundDetected = false;}
|
||||||
// Ledge Detection
|
// Ledge Detection
|
||||||
public void OnLedgeEntered(Area2D area){if (area.CollisionLayer == 0) LedgeDetected = true;}
|
public void OnLedgeEntered(Node2D body){if (body is TileMapLayer tileLayer) LedgeDetected = true;}
|
||||||
public void OnLedgeExited(Area2D area){if (area.CollisionLayer == 0) LedgeDetected = false;}
|
public void OnLedgeExited(Node2D body){if (body is TileMapLayer tileLayer) LedgeDetected = false;}
|
||||||
|
// Wall Detection
|
||||||
|
public void OnWallEntered(Node2D body){if (body is TileMapLayer tileLayer) WallDetected = true;}
|
||||||
|
public void OnWallExited(Node2D body){if (body is TileMapLayer tileLayer) WallDetected = false;}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,22 +137,25 @@ metadata/AbilityRegenerate = true
|
|||||||
[node name="GroundDetector" type="Area2D" parent="."]
|
[node name="GroundDetector" type="Area2D" parent="."]
|
||||||
position = Vector2(1.1368684e-13, 10.999999)
|
position = Vector2(1.1368684e-13, 10.999999)
|
||||||
scale = Vector2(0.099999994, 0.099999994)
|
scale = Vector2(0.099999994, 0.099999994)
|
||||||
|
collision_layer = 0
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="GroundDetector"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="GroundDetector"]
|
||||||
scale = Vector2(0.99999994, 0.99999994)
|
scale = Vector2(0.99999994, 0.99999994)
|
||||||
shape = SubResource("RectangleShape2D_bc7hl")
|
shape = SubResource("RectangleShape2D_bc7hl")
|
||||||
|
|
||||||
[node name="LedgeDetector" type="Area2D" parent="."]
|
[node name="LedgeDetector" type="Area2D" parent="."]
|
||||||
|
collision_layer = 0
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="LedgeDetector"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="LedgeDetector"]
|
||||||
position = Vector2(12, 12)
|
position = Vector2(14, 14)
|
||||||
scale = Vector2(0.1, 0.1)
|
scale = Vector2(0.1, 0.1)
|
||||||
shape = SubResource("RectangleShape2D_bc7hl")
|
shape = SubResource("RectangleShape2D_bc7hl")
|
||||||
|
|
||||||
[node name="WallDetector" type="Area2D" parent="."]
|
[node name="WallDetector" type="Area2D" parent="."]
|
||||||
|
collision_layer = 0
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="WallDetector"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="WallDetector"]
|
||||||
position = Vector2(12, 9.536743e-07)
|
position = Vector2(14, 9.536743e-07)
|
||||||
scale = Vector2(0.1, 0.1)
|
scale = Vector2(0.1, 0.1)
|
||||||
shape = SubResource("RectangleShape2D_bc7hl")
|
shape = SubResource("RectangleShape2D_bc7hl")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user