What should I add in Create Event of player object? //Create Event of objBox isHeld =…
- User
What should I add in Create Event of player object?
//Create Event of objBox isHeld = false; // Indicates if the box is being carried heldBy = noone; // Reference to the player instance holding the box
//Step Event of objBox if (isHeld && instance_exists(heldBy)) { var player = heldBy;
// Define offsets based on player's direction var offsetX = player.image_xscale * 40; // 40 pixels to the side var offsetY = -player.sprite_get_height(player.sprite_index) / 2; // Adjust vertically // Smoothly follow the player (optional) x = lerp(x, player.x + offsetX, 0.5); y = lerp(y, player.y + offsetY, 0.5);}
//part of playerStep if (keyboard_check_pressed(ord("E"))) { if (!carryingBox) { // Attempt to pick up a box var box = instance_nearest(x, y, objBox); var pickupRange = 32;
if (box != noone && point_distance(x, y, box.x, box.y) <= pickupRange && !box.isHeld) { carryingBox = true; heldBox = box; box.isHeld = true; box.heldBy = id; } } else { // Attempt to put down the box if (heldBox != noone) { var dropX = x + image_xscale * 40; var dropY = y - sprite_get_height(sprite_index) / 2; // Check for collision at drop position if (!place_meeting(dropX, dropY, objSolid) && !place_meeting(dropX, dropY, objTopSolid)) { // Place the box heldBox.x = dropX; heldBox.y = dropY; heldBox.isHeld = false; heldBox.heldBy = noone; // Update carrying state carryingBox = false; heldBox = noone; } } } } - Assistant