I want to start making a 2D RPG game but I am stuck trying to get the player to not be able to walk through objects and I can't figure it out. I would like it so when I walk into/hit the rock, the player will stop moving in that direstion so the rock is a barrier. Can someone help me as soon as you can please.
from ursina import *
class Player(Entity):
def __init__(self, x, y, speed):
super().__init__()
self.model="quad"
self.scale=1
self.x=x
self.y=y
self.speed=speed
self.texture="player_idle.png"
self.collider='box'
def update(self):
self.x+=(held_keys['d'] - held_keys['a'])*time.dt*speed
self.y+=(held_keys['w'] - held_keys['s'])*time.dt*speed
def input(self, key):
if key=='w':
self.texture='player_walk_1.png'
if key=='s':
self.texture='player_idle.png'
if key=='d':
self.texture='player_walk_right.png'
if key=='a':
self.texture='player_walk_left.png'
app=Ursina()
rock=Entity(model="quad", scale=1, position=(0,4,1),
texture="rock.png", collider='box')
x=-2
y=-1
size=1
speed=3
player=Player(x, y, speed)
for m in range (8):
duplicate(rock, x=size*(m+1))
duplicate(rock, x=-size*(m+1))
app.run()