0

Ok in my code i was trying to get the camera to follow my player and i was following a tutorial i found on stack overflow. But when I did it the player "fell" and rotates on its y axis how did this happen and also I tried to spawn the ground class but i dont think i did. And looked on all the docs for ursina and looking at how to videos, I still dont understand why. wht did i do wrong?

from ursina import *

from ursina.prefabs.first_person_controller import FirstPersonController



app = Ursina()

EditorCamera()
cam = FirstPersonController()


class Player(Entity):
    def __init__(self, **kwargs):
        super().__init__(model='cube', color=color.orange, collider='box', origin = (0, 0, -2), parent = cam)
        self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
        self.max_health = 100
        self.health = self.max_health








      


class Beings(Entity):
    def __init__(self, **kwargs):
        super().__init__(model='cube', color=color.gray, scale=2, collider='box', position=Vec3(1,0,2), origin_y=-.5)
        self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
        self.max_health = 100
        self.health = self.max_health

       

class Ground(Entity):
    def __init__(self, **kwargs):
        super().__init__(model='plane', color=color.gray, scale=2, collider='mesh', position=Vec3(1,0,2), origin_y=-.4)
        self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
        self.max_health = 100
        self.health = self.max_health

class Buildings(Entity):
     def __init__(self, **kwargs):
        super().__init__(model='cube', color=color.gray, scale=2, collider='box', position=Vec3(1,0,2), origin_y=-.5)
        self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
        self.max_health = 100
        self.health = self.max_health


class plants(Entity):
     def __init__(self, **kwargs):
        super().__init__(model='cube', color=color.gray, scale=2, collider='box', position=Vec3(1,0,2), origin_y=-.5)
        self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
        self.max_health = 100
        self.health = self.max_health

class Earth(Entity):
     def __init__(self, **kwargs):
        super().__init__(model='cube', color=color.gray, scale=2, collider='box', position=Vec3(1,0,2), origin_y=-.5)
        self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
        self.max_health = 100
        self.health = self.max_health


     






b = Beings()
p = Player()


def update():
          
    Ground()
    p.z += (held_keys['w'] - held_keys['s']) * time.dt * 6
    p.x += (held_keys['d'] - held_keys['a']) * time.dt * 6
   

    if p.intersects(b).hit:
             b.color = color.lime
             print('player is inside trigger box')
    else:
          b.color = color.gray

app.run()
Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52

2 Answers2

0

It's falling because the ground is above the bottom of the player. This can be solved by moving the ground down, for example with y=-1. Also, setting origin_y to a negative value like you did will move the model and collider up.

pokepetter
  • 1,383
  • 5
  • 8
0

I think this will help you. You had to change the y coordinate of the ground and the player:

    from ursina import *

from ursina.prefabs.first_person_controller import FirstPersonController


app = Ursina()

# EditorCamera()
# cam = FirstPersonController(y=5)


class Player(FirstPersonController):
    def __init__(self, **kwargs):
        super().__init__(model='cube', color=color.orange, collider='box')
        self.y=5
        self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
        self.max_health = 100
        self.health = self.max_health
        self.origin = (0, 0, -1)

# camera.position=(0, 1, -3)


class Beings(Entity):
    def __init__(self, **kwargs):
        super().__init__(model='cube', color=color.gray, scale=2, collider='box', position=Vec3(1,0,2), origin_y=-.5)
        self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
        self.max_health = 100
        self.health = self.max_health

    

class Ground(Entity):
    def __init__(self, **kwargs):
        super().__init__(model='plane', texture_scale=(50, 50), texture='white_cube', scale=50, collider='mesh', position=Vec3(1,0,2))
        self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
        self.max_health = 100
        self.health = self.max_health
        self.y = -1 #change this as per your requirment
        self.texture='white_cube'

class Buildings(Entity):
    def __init__(self, **kwargs):
        super().__init__(model='cube', color=color.gray, scale=2, collider='box', position=Vec3(1,0,2), origin_y=-.5)
        self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
        self.max_health = 100
        self.health = self.max_health


class plants(Entity):
    def __init__(self, **kwargs):
        super().__init__(model='cube', color=color.gray, scale=2, collider='box', position=Vec3(1,0,2), origin_y=-.5)
        self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
        self.max_health = 100
        self.health = self.max_health

class Earth(Entity):
    def __init__(self, **kwargs):
        super().__init__(model='cube', color=color.gray, scale=2, collider='box', position=Vec3(1,0,2), origin_y=-.5)
        self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
        self.max_health = 100
        self.health = self.max_health


    






b = Beings()
p = Player()
g = Ground()

def update():
        
    


    if p.intersects(b).hit:
            b.color = color.lime
            print('player is inside trigger box')
    else:
        b.color = color.gray

app.run()
Tanay
  • 561
  • 1
  • 3
  • 16