我已经问了我的 A.I.,为什么公主皮尔奇一直掉落在这个平台上,它一直给出同样的答案,比如说,调整碰撞掩码与整个平台的对齐。所以我就那样做了,她还是掉落了。是什么地方出错了?

为了背景:我展示的图片是我的游戏在测试时的样子。她的确是掉落在 ElderStar 上的平台上,只有平台是可见的。什么地方出错了? 是编程问题吗? 是碰撞掩码问题吗? 是问题真的很简单,我是在把它搞复杂了吗? 是什么?!

更新: 对不起 guys,我不是很擅长编程,所以请耐心等待,如果代码有问题。 我正在尝试制作一个游戏,我使用 A.I. 来帮助编程方面。

[图片链接]

Obj_PrincessPeach_New 的 Create Event:

hsp = 0;

vsp = 0;

move_speed = 7;

gravity = 0.6;

jump_speed = -12;

on_ground = false;

Obj_PrincessPeach_New 的 Step Event:

/// ===============================

/// 公主皮尔奇 —— 步骤事件

/// ===============================

// 1. 输入 & 重力

var key_x = keyboard_check(vk_right) - keyboard_check(vk_left);

var pad_x = gamepad_axis_value(0, gp_axislh);

var deadzone = 0.25;

if (abs(pad_x) < deadzone) pad_x = 0;

var move_x = key_x + pad_x;

hsp = move_x * move_speed;

if (!on_ground) vsp += gravity;

if (keyboard_check_pressed(vk_space) && on_ground) {

vsp = jump_speed;

on_ground = false;

}

// 2. 水平碰撞

if (hsp != 0) {

if (place_meeting(x + hsp, y, Obj_Platform)) {

while (!place_meeting(x + sign(hsp), y, Obj_Platform)) x += sign(hsp);

hsp = 0;

} else {

x += hsp;

}

}

// ===============================

// 垂直碰撞 & 运动

// ===============================

var hit_instance = noone;

if (on_ground) {

hit_instance = instance_place(x, bbox_bottom + 1, Obj_Platform);

} else {

hit_instance = instance_place(x, y + vsp, Obj_Platform);

}

if (hit_instance != noone) {

if (vsp > 0) {

y = hit_instance.bbox_top - (bbox_bottom - y) - 1;

on_ground = true;

} else if (vsp < 0) {

y = hit_instance.bbox_bottom + (y - bbox_top) + 1;

on_ground = false;

} else {

on_ground = true;

}

vsp = 0;

} else {

// ✅ 诊断代码在这里 - 在这个 else 块内

var left_plat = instance_place(x - 5, y + vsp, Obj_Platform);

var right_plat = instance_place(x + 5, y + vsp, Obj_Platform);

if (left_plat != noone && right_plat != noone) {

show_debug_message("掉落在缝隙中!左边=" + string(left_plat) + " 右边=" + string(right_plat));

}

// 应用重力和移动

vsp += gravity;

y += vsp;

on_ground = false;

}

// 4. 动画 (必须在物理之后)

if (move_x != 0) image_xscale = sign(move_x);

if (!on_ground) {

image_speed = 0;

} else {

if (move_x == 0) {

sprite_index = PrincessPeach_Idle;

image_speed = 0.2;

} else {

sprite_index = PrincessPeach_Walking;

image_speed = 0.3;

}

}

Obj_PrincessPeach_New 的 Draw Event:

// 只绘制如果精灵存在并且有有效的边界框

if (sprite_exists(sprite_index)) {

draw_self();

// 验证 bbox 值之前绘制

if (bbox_left >= 0 && bbox_right >= 0 && bbox_top >= 0 && bbox_bottom >= 0) {

draw_rectangle_color(bbox_left, bbox_top, bbox_right, bbox_bottom, c_red, c_red, c_red, c_red, false);

}

} else {

// fallback:绘制一个简单的占位符,以便你仍然可以看到皮尔奇

draw_circle_color(x, y, 16, c_yellow, c_yellow, false);