Skip to content

Commit 55ecb23

Browse files
committed
activation/activators
1 parent 8c9bc99 commit 55ecb23

File tree

8 files changed

+82
-10
lines changed

8 files changed

+82
-10
lines changed

datafiles/meshes.derg

320 Bytes
Binary file not shown.

objects/obj_3d_pressure_plate/Create_0.gml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ self.Deactivate = function() {
99
};
1010

1111
self.GetActivationZone = function() {
12-
var index = array_find_index(self.mesh.collision_shapes, function(item) {
13-
return item.name == "#Activation";
14-
});
12+
var index = array_search_with_name(self.mesh.collision_shapes, "#Activation");
1513
return self.cobjects[index];
1614
};
1715

objects/obj_3d_seesaw/Create_0.gml

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ self.cobject_block_left = new ColObject(shape_block_left.shape, self, shape_bloc
1616
var shape_block_right = col_shape_from_penguin(self.mesh_block_right.collision_shapes[0], ECollisionMasks.DEFAULT, ECollisionMasks.DEFAULT);
1717
self.cobject_block_right = new ColObject(shape_block_right.shape, self, shape_block_right.shape_mask, shape_block_right.shape_group);
1818

19+
var shape_activation_left = col_shape_from_penguin(array_search_with_name(self.mesh_block_left.collision_shapes, "#Activation"));
20+
self.cobject_activation_left = new ColObject(shape_activation_left.shape, self, shape_activation_left.shape_mask, shape_activation_left.shape_group);
21+
22+
var shape_activation_right = col_shape_from_penguin(array_search_with_name(self.mesh_block_right.collision_shapes, "#Activation"));
23+
self.cobject_activation_right = new ColObject(shape_activation_right.shape, self, shape_activation_right.shape_mask, shape_activation_right.shape_group);
24+
1925
self.seesaw_angle = 0;
2026

2127
self.matrix_base = undefined;
@@ -49,6 +55,22 @@ self.CalculateAllPositions = function() {
4955
col_object_update_position(self.cobject_seesaw, self.matrix_seesaw);
5056
col_object_update_position(self.cobject_block_left, self.matrix_block_left);
5157
col_object_update_position(self.cobject_block_right, self.matrix_block_right);
58+
59+
col_object_update_position(self.cobject_activation_left, self.matrix_block_left);
60+
col_object_update_position(self.cobject_activation_right, self.matrix_block_right);
61+
};
62+
63+
self.HandleActivation = function() {
64+
var is_left = obj_game.collision.CheckObject(self.cobject_activation_left);
65+
var is_right = obj_game.collision.CheckObject(self.cobject_activation_right);
66+
67+
if (is_left && !is_right) {
68+
self.state.change("tilt_left");
69+
} else if (is_right && !is_left) {
70+
self.state.change("tilt_right")
71+
} else if (is_left && is_right) {
72+
self.state.change("balanced")
73+
}
5274
};
5375

5476
self.state = new SnowState("balanced")
@@ -57,19 +79,38 @@ self.state = new SnowState("balanced")
5779
static turn_rate = 120;
5880
self.seesaw_angle = approach(self.seesaw_angle, 0, turn_rate * DT);
5981
self.CalculateAllPositions();
82+
self.HandleActivation();
6083
}
6184
})
6285
.add("tilt_left", {
6386
update: function() {
6487
static turn_rate = 120;
65-
self.seesaw_angle = approach(self.seesaw_angle, -15, turn_rate * DT);
88+
static target_angle = 15;
89+
self.seesaw_angle = approach(self.seesaw_angle, target_angle, turn_rate * DT);
6690
self.CalculateAllPositions();
91+
if (self.seesaw_angle == target_angle) {
92+
self.state.change("left");
93+
}
6794
}
6895
})
6996
.add("tilt_right", {
7097
update: function() {
7198
static turn_rate = 120;
72-
self.seesaw_angle = approach(self.seesaw_angle, 15, turn_rate * DT);
99+
static target_angle = -15;
100+
self.seesaw_angle = approach(self.seesaw_angle, target_angle, turn_rate * DT);
73101
self.CalculateAllPositions();
102+
if (self.seesaw_angle == target_angle) {
103+
self.state.change("left");
104+
}
105+
}
106+
})
107+
.add("left", {
108+
update: function() {
109+
self.HandleActivation();
110+
}
111+
})
112+
.add("right", {
113+
update: function() {
114+
self.HandleActivation();
74115
}
75-
});
116+
});

objects/obj_game/Create_0.gml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,17 @@ var map = new UnityMapImport("test.place", self.meshes);
8888
var seesaw = instance_create_depth(100, 0, -300, obj_3d_seesaw);
8989
seesaw.UpdateCollisionPositions();
9090

91+
var block = instance_create_depth(228, 100, -300, obj_3d_spell_block);
92+
block.SetMesh(self.meshes.block);
93+
block.UpdateCollisionPositions();
94+
9195
enum ECollisionMasks {
9296
NONE = 0b_0000_0000,
9397
DEFAULT = 0b_0000_0001,
9498
CLIMBABLE = 0b_0000_0010,
9599
MOVING = 0b_0000_0100,
96100
SPELL_TARGET = 0b_0000_1000,
97-
PICKUP = 0b_0001_0000
101+
PICKUP = 0b_0001_0000,
102+
103+
ACTIVATOR = 0b_0010_0000
98104
}

objects/obj_npc/Create_0.gml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ event_inherited();
33
self.radius = 16;
44

55
self.cshape = new ColSphere(new Vector3(0, self.radius, 0), self.radius);
6-
self.cobject = new ColObject(self.cshape, self.id, 1, 1);
6+
self.cobject = new ColObject(self.cshape, self.id, ECollisionMasks.DEFAULT, ECollisionMasks.DEFAULT);
77

88
self.IsGrounded = function() {
99
if (self.y <= 0) return true;

objects/obj_player/Create_0.gml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ self.state.add("default", {
2828
if (!self.IsGrounded()) {
2929
self.state.change("airborne");
3030
}
31+
32+
self.UpdateActivatorPosition();
3133
}
3234
}).add("airborne", {
3335
enter: function() {
@@ -154,6 +156,15 @@ climb_shape.original_position = original_position.Mul(1);
154156
self.cobject_climb = new ColObject(climb_shape, self.id, ECollisionMasks.NONE, ECollisionMasks.CLIMBABLE);
155157
#endregion
156158

159+
#region special collision object - pressure plate activator
160+
var player_activator_collision = array_search_with_name(player_data.collision_shapes, "#Activator");
161+
162+
original_position = new Vector3(player_activator_collision.position.x, player_activator_collision.position.y, player_activator_collision.position.z);
163+
var activator_shape = new ColSphere(original_position, player_climb_collision.radius);
164+
activator_shape.original_position = original_position.Mul(1);
165+
self.cobject_activator = new ColObject(activator_shape, self.id, ECollisionMasks.ACTIVATOR, ECollisionMasks.NONE);
166+
#endregion
167+
157168
#region Special collision object - camera target
158169
self.camera_target = array_search_with_name(player_data.collision_shapes, "#CameraTarget").position;
159170

@@ -303,6 +314,16 @@ self.HandleClimbing = function() {
303314
}
304315
};
305316

317+
self.UpdateActivatorPosition = function() {
318+
var activator_position = self.cobject_activator.shape.original_position;
319+
var player_transform = matrix_build(self.x, self.y, self.z, 0, self.direction, 0, 1, 1, 1);
320+
var climb_target_transformed = matrix_transform_vertex(player_transform, activator_position.x, activator_position.y, activator_position.z);
321+
self.cobject_activator.shape.Set(new Vector3(climb_target_transformed[0], climb_target_transformed[1], climb_target_transformed[2]));
322+
323+
obj_game.collision.Remove(self.cobject_activator);
324+
obj_game.collision.Add(self.cobject_activator);
325+
};
326+
306327
self.HandleCasting = function() {
307328
static spell_velocity = 640;
308329
static max_spell_range = 640;

scripts/Group_Common_Library/Group_Common_Library.gml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ function surface_validate(surface, w, h, format = surface_rgba8unorm) {
99
return surface_create(w, h, format);
1010
}
1111

12+
/// @param {array<struct>} array
13+
/// @param {string} name
1214
function array_search_with_name(array, name) {
1315
var index = array_find_index(array, method({ name }, function(shape) {
1416
return shape.name == self.name;

scripts/col_shape_from_penguin/col_shape_from_penguin.gml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function col_shape_from_penguin(shape_data, mask, group) {
1+
function col_shape_from_penguin(shape_data, mask = ECollisionMasks.DEFAULT, group = ECollisionMasks.DEFAULT) {
22
var shape_mask = mask;
33
var shape_group = group;
44

@@ -22,7 +22,11 @@ function col_shape_from_penguin(shape_data, mask, group) {
2222
break;
2323
case "#Activation":
2424
shape_mask = ECollisionMasks.NONE;
25-
shape_group = ECollisionMasks.DEFAULT;
25+
shape_group = ECollisionMasks.ACTIVATOR;
26+
break;
27+
case "#Activator":
28+
shape_mask = ECollisionMasks.ACTIVATOR;
29+
shape_group = ECollisionMasks.NONE;
2630
break;
2731
}
2832
}

0 commit comments

Comments
 (0)