Я делаю игру-лабиринт с урсиной, но не могу заставить игрока не проходить сквозь стену. Я пытался добавить коллайдер, но он ничего не делает, потому что мне нужно проверять коллизии, а не давать им коды для выполнения. Я добавил 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
Программы на Python
-
Anonymous
1736273211
Anonymous
Я делаю игру-лабиринт с урсиной, но не могу заставить игрока не проходить сквозь стену. Я пытался добавить коллайдер, но он ничего не делает, потому что мне нужно проверять коллизии, а не давать им коды для выполнения. Я добавил 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()
Подробнее здесь: [url]https://stackoverflow.com/questions/78894850/how-to-let-a-player-not-moving-through-the-another-entity2d[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия