Я делаю игру-лабиринт с урсиной, но не могу заставить игрока не проходить сквозь стену. Я пытался добавить коллайдер, но он ничего не делает, потому что мне нужно проверять коллизии, а не давать им коды для выполнения. Я добавил raycast, но он делает то же самое, что и коллайдер. Пожалуйста, помогите мне
Вот мой код.
from ursina import *
from ursina import physics
class top_down_controller(Entity):
def __init__(self, model, color, scale = 1, texture = None, collider = 'box', ignore=[], position=[0,0]):
super().__init__(
model = model,
color = color,
scale = scale,
texture = texture,
collider = collider,
ignore = ignore,
vleft = -0.1,
vright = 0.1,
vup = 0.1,
vdown = -0.1,
position= position
)
def update(self):
self.x += held_keys['a'] * self.vleft
self.x += held_keys["d"] * self.vright
self.y += held_keys['w'] * self.vup
self.y += held_keys['s'] * self.vdown
above = raycast(self.world_position, self.up, 0.51, ignore=[self], debug = True)
above_left = raycast(self.world_position+Vec3(-0.5,0,0), self.up, 0.51, ignore = [self], debug = True)
above_right = raycast(self.world_position+Vec3(0.5,0,0), self.up, 0.51, ignore = [self], debug = True)
below = raycast(self.world_position, self.down, 0.51, ignore = [self], debug = True)
below_left = raycast(self.world_position+Vec3(-0.5,0,0), self.down, 0.51, ignore = [self], debug = True)
below_right = raycast(self.world_position+Vec3(0.5,0,0), self.down, 0.51, ignore = [self], debug = True)
left = raycast(self.world_position, self.left, 0.51, ignore = [self], debug = True)
left_above = raycast(self.world_position+Vec3(0,0.5,0), self.left, 0.51, ignore = [self], debug = True)
left_down = raycast(self.world_position+Vec3(0,-0.5,0), self.left, 0.51, ignore = [self], debug = True)
right = raycast(self.world_position, self.right, 0.51, ignore = [self], debug=True)
right_above = raycast(self.world_position+Vec3(0,0.5,0), self.right, 0.51, ignore = [self], debug = True)
right_down = raycast(self.world_position+Vec3(0,-0.5,0), self.right, 0.51, ignore = [self], debug = True)
if any((above.hit, above_left.hit, above_right.hit)):
self.vup = 0
elif any((left.hit, left_above.hit, left_down.hit)):
self.vleft = 0
elif any((right.hit, right_above.hit, right_down.hit)):
self.vright = 0
elif any((below_right.hit, below.hit, below_left.hit)):
self.vdown = 0
app = Ursina()
e1 = Entity(model = 'quad', color = color.green, collider = 'box')
e = top_down_controller(model = 'quad', color = color.blue, position = [2,2], ignore = [e1])
app.run()
Подробнее здесь: https://stackoverflow.com/questions/788 ... r-entity2d
Как позволить игроку не перемещаться через другой объект (2d)? ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение