Skip to content

Commit cc5aea7

Browse files
committed
if a rotor hits something, it'll bounce off and go back to its starting position
1 parent ce1dc02 commit cc5aea7

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

objects/obj_3d_spell_rotor/Create_0.gml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
event_inherited();
22

33
self.rotor_direction = self.target_direction;
4+
self.rotor_start_direction = self.rotor_direction;
45

56
self.state = new SnowState("still", false)
67
.add("still", {
@@ -16,6 +17,7 @@ self.state = new SnowState("still", false)
1617
var vector_to_rotor = hit_info.shape.position.Sub(new Vector3(self.x, self.y, self.z));
1718
var direction_to_rotor = point_direction(0, 0, vector_to_rotor.x, vector_to_rotor.z);
1819

20+
self.rotor_start_direction = self.rotor_direction;
1921
if (angle_difference(direction_to_hit, direction_to_rotor) > 0) {
2022
self.target_direction = self.rotor_direction + 90;
2123
} else {
@@ -26,11 +28,18 @@ self.state = new SnowState("still", false)
2628
})
2729
.add("turning", {
2830
update: function() {
29-
self.rotor_direction = approach(self.rotor_direction, self.target_direction, 1);
31+
static rotation_speed = 150;
32+
self.rotor_direction = approach(self.rotor_direction, self.target_direction, rotation_speed * DT);
3033

3134
self.rotation_mat = matrix_build(0, 0, 0, 0, self.rotor_direction, 0, 1, 1, 1);
3235
self.UpdateCollisionPositions();
3336

37+
array_foreach(self.cobjects, function(cobject) {
38+
if (obj_game.collision.CheckObject(cobject)) {
39+
self.target_direction = self.rotor_start_direction;
40+
}
41+
});
42+
3443
if (self.rotor_direction == self.target_direction) {
3544
self.state.change("still");
3645
}

objects/obj_game/Create_0.gml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ var map = new UnityMapImport("test.place", self.meshes);
9090
var seesaw = instance_create_depth(100, 0, -300, obj_3d_seesaw);
9191
seesaw.UpdateCollisionPositions();
9292

93-
var block = instance_create_depth(228, 100, -300, obj_3d_spell_block);
94-
block.SetMesh(self.meshes.block);
95-
block.UpdateCollisionPositions();
96-
9793
var rotor_1 = instance_create_depth(100 - 128, 0, -450, obj_3d_spell_rotor);
9894
rotor_1.SetMesh(self.meshes.rotor_3);
9995
rotor_1.UpdateCollisionPositions();
10096

97+
var block = instance_create_depth(rotor_1.x + 20, 0, rotor_1.z + 20, obj_3d_spell_block);
98+
block.SetMesh(self.meshes.block);
99+
block.UpdateCollisionPositions();
100+
101101
enum ECollisionMasks {
102102
NONE = 0b_0000_0000,
103103
DEFAULT = 0b_0000_0001,

scripts/Col_World/Col_World.gml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function ColObject(shape, reference, mask = 1, group = 1) constructor {
88
static CheckObject = function(object) {
99
if (object == self) return false;
1010
if ((self.mask & object.group) == 0) return false;
11+
if (object.reference == self.reference) return false;
1112
return self.shape.CheckObject(object);
1213
};
1314

0 commit comments

Comments
 (0)