File tree Expand file tree Collapse file tree 3 files changed +23
-6
lines changed
Expand file tree Collapse file tree 3 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -24,9 +24,10 @@ script = ExtResource("3_urblq")
2424position = Vector2 (-174 , 28 )
2525grid = NodePath ("../../Tiles/Layer0" )
2626
27- [node name ="FreeMovementTroll" parent ="TrollSpawner" instance =ExtResource ("2" )]
27+ [node name ="FreeMovementTroll" parent ="TrollSpawner" node_paths = PackedStringArray ( "grid" ) instance =ExtResource ("2" )]
2828modulate = Color (1.5 , 1.5 , 1.5 , 1 )
2929position = Vector2 (3.81897 , -137.288 )
30+ grid = NodePath ("../../Tiles/Layer0" )
3031
3132[node name ="CanvasLayer" type ="CanvasLayer" parent ="." ]
3233
Original file line number Diff line number Diff line change 11extends CharacterBody2D
22
3- const MOTION_SPEED = 30
4- const FRICTION_FACTOR = 0.89
5- const TAN30DEG = tan (deg_to_rad (30 ))
3+ const MOTION_SPEED : float = 30.0
4+ const FRICTION_FACTOR : float = 0.89
5+ const TAN30DEG : float = tan (deg_to_rad (30.0 ))
6+
7+
8+ @export var grid : TileMapLayer
69
710
811func become_active_troll () -> void :
912 pass
1013
1114
1215func _physics_process (_delta : float ) -> void :
16+ var prev_position : Vector2 = global_position
17+
1318 var motion := Vector2 ()
1419 motion .x = Input .get_axis (& "move_left" , & "move_right" )
1520 motion .y = Input .get_axis (& "move_up" , & "move_down" )
@@ -19,3 +24,12 @@ func _physics_process(_delta: float) -> void:
1924 # Apply friction.
2025 velocity *= FRICTION_FACTOR
2126 move_and_slide ()
27+
28+
29+ # Prevent movement off of the grid tiles. Alternatively, you could add a
30+ # border tile around the outside of your world with physics enabled in the
31+ # TileMapLayer. That would allow nice sliding along the walls of the world.
32+ var dest_tile : int = grid .get_world_tile (global_position )
33+ var has_tile : bool = dest_tile >= 0
34+ if not has_tile :
35+ global_position = prev_position
Original file line number Diff line number Diff line change @@ -10,19 +10,21 @@ radius = 16.0
1010script = ExtResource ("1" )
1111
1212[node name ="Sprite2D" type ="Sprite2D" parent ="." ]
13+ position = Vector2 (-3.74084 , -19.5 )
1314texture = ExtResource ("2" )
1415
1516[node name ="Shadow" type ="Sprite2D" parent ="." ]
1617modulate = Color (0 , 0 , 0 , 0.501961 )
1718show_behind_parent = true
18- position = Vector2 (16.4422 , 4.89438 )
19+ position = Vector2 (12.7014 , -14.6056 )
1920scale = Vector2 (0.794259 , 1.04505 )
2021skew = 0.523599
2122texture = ExtResource ("2" )
2223
2324[node name ="CollisionShape2D" type ="CollisionShape2D" parent ="." ]
24- position = Vector2 (3.24216 , 19.453 )
25+ position = Vector2 (-0.498685 , -0.0470009 )
2526shape = SubResource ("1" )
2627
2728[node name ="Camera2D" type ="Camera2D" parent ="." ]
29+ position = Vector2 (-3.74084 , -19.5 )
2830process_callback = 0
You can’t perform that action at this time.
0 commit comments