Skip to content

Commit f08df2b

Browse files
committed
Fix look_at_from_position() usage in Squash the Creeps (3D)
The mob's orientation was previously shifted according to the player's height, which could lead to collision and movement issues that were difficult to diagnose.
1 parent 0d46333 commit f08df2b

File tree

6 files changed

+23
-12
lines changed

6 files changed

+23
-12
lines changed

3d/squash_the_creeps/Main.tscn

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[ext_resource type="PackedScene" uid="uid://dp478jyugrn7o" path="res://Player.tscn" id="2"]
55
[ext_resource type="PackedScene" uid="uid://ha0ar5s2c3m4" path="res://Mob.tscn" id="3"]
66
[ext_resource type="Theme" uid="uid://cqquurjk1i7yw" path="res://ui_theme.tres" id="4_gnyca"]
7-
[ext_resource type="Script" path="res://ScoreLabel.gd" id="6"]
7+
[ext_resource type="Script" uid="uid://bb26jybfvgwdk" path="res://ScoreLabel.gd" id="6"]
88

99
[sub_resource type="BoxShape3D" id="1"]
1010
size = Vector3(60, 2, 60)

3d/squash_the_creeps/Mob.gd

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ func _physics_process(_delta):
1414

1515

1616
func initialize(start_position, player_position):
17-
look_at_from_position(start_position, player_position, Vector3.UP)
17+
# Ignore the player's height, so that the mob's orientation is not slightly
18+
# shifted if the mob spawns while the player is jumping.
19+
var target = Vector3(player_position.x, start_position.y, player_position.z)
20+
look_at_from_position(start_position, target, Vector3.UP)
21+
22+
# Rotate this mob randomly within range of -45 and +45 degrees,
23+
# so that it doesn't move directly towards the player.
1824
rotate_y(randf_range(-PI / 4, PI / 4))
1925

2026
var random_speed = randf_range(min_speed, max_speed)

3d/squash_the_creeps/art/mob.glb.import

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ nodes/root_type="Spatial"
1717
nodes/root_name="Scene Root"
1818
nodes/apply_root_scale=true
1919
nodes/root_scale=1.0
20+
nodes/import_as_skeleton_bones=false
2021
meshes/ensure_tangents=true
2122
meshes/generate_lods=false
2223
meshes/create_shadow_meshes=true
@@ -28,6 +29,7 @@ animation/import=true
2829
animation/fps=15
2930
animation/trimming=false
3031
animation/remove_immutable_tracks=true
32+
animation/import_rest_as_RESET=false
3133
import_script/path=""
3234
_subresources={}
3335
gltf/naming_version=0

3d/squash_the_creeps/art/player.glb.import

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ nodes/root_type="Spatial"
1717
nodes/root_name="Scene Root"
1818
nodes/apply_root_scale=true
1919
nodes/root_scale=1.0
20+
nodes/import_as_skeleton_bones=false
2021
meshes/ensure_tangents=true
2122
meshes/generate_lods=false
2223
meshes/create_shadow_meshes=true
@@ -28,6 +29,7 @@ animation/import=true
2829
animation/fps=15
2930
animation/trimming=false
3031
animation/remove_immutable_tracks=true
32+
animation/import_rest_as_RESET=false
3133
import_script/path=""
3234
_subresources={}
3335
gltf/naming_version=0

3d/squash_the_creeps/fonts/Montserrat-Medium.ttf.import

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dest_files=["res://.godot/imported/Montserrat-Medium.ttf-e832861e4ad4110e172112d
1515
Rendering=null
1616
antialiasing=1
1717
generate_mipmaps=false
18+
disable_embedded_bitmaps=true
1819
multichannel_signed_distance_field=false
1920
msdf_pixel_range=8
2021
msdf_size=48

3d/squash_the_creeps/project.godot

+10-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This is a finished version of the game featured in the \"Your first 3D game\"
1717
tutorial in the official documentation."
1818
config/tags=PackedStringArray("3d", "demo", "official")
1919
run/main_scene="res://Main.tscn"
20-
config/features=PackedStringArray("4.2")
20+
config/features=PackedStringArray("4.3")
2121
config/icon="res://icon.webp"
2222

2323
[autoload]
@@ -37,35 +37,35 @@ import/blender/enabled=false
3737

3838
move_left={
3939
"deadzone": 0.2,
40-
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
41-
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":113,"echo":false,"script":null)
40+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
41+
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":113,"location":0,"echo":false,"script":null)
4242
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
4343
]
4444
}
4545
move_right={
4646
"deadzone": 0.2,
47-
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null)
48-
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null)
47+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
48+
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
4949
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
5050
]
5151
}
5252
move_forward={
5353
"deadzone": 0.2,
54-
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"echo":false,"script":null)
55-
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":122,"echo":false,"script":null)
54+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
55+
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":122,"location":0,"echo":false,"script":null)
5656
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
5757
]
5858
}
5959
move_back={
6060
"deadzone": 0.2,
61-
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"echo":false,"script":null)
62-
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null)
61+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
62+
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
6363
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
6464
]
6565
}
6666
jump={
6767
"deadzone": 0.2,
68-
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"echo":false,"script":null)
68+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
6969
, Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":2,"canceled":false,"pressed":false,"double_click":false,"script":null)
7070
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":0,"pressure":0.0,"pressed":false,"script":null)
7171
]

0 commit comments

Comments
 (0)