0

My Issue

I am using the Panda3D wrapper for Python to run some 1st person game tests. I would like the collider of the ursina camera type called the FirstPersonController to extend its collider over the sprite. I have tried (without really knowing how as there aren't many tutorials on Ursina) using a BoxCollider() but I didn't really get how to do it. Can anyone help me?

My Code

from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController



class Player(Entity):
    def __init__(self, parent):
        super().__init__(    # super() is used to access things from the inheriting class (in this case the Entity class)
            model = 'cube',
            color = color.red,
            parent = parent
        )
        
        
class Floor(Entity):
    def __init__(self):
        super().__init__(
            model = 'cube',
            scale = (40, 3, 40),
            color = color.rgb(23, 45, 105),
            position = (0, -20, 0),
            collider = 'box'
        )




app = Ursina()

window.fps_counter.enabled = False
window.fullscreen = True



cam = FirstPersonController()
player = Player(cam)


floor = Floor()



def update():
    if held_keys['escape']:
        application.quit()

Sky()
app.run()

Please help, all suggestions are helpful!

Jan Wilamowski
  • 3,308
  • 2
  • 10
  • 23
SamTheProgrammer
  • 1,051
  • 1
  • 10
  • 28
  • 1
    what do you mean by extending the collider? avoiding clipping into other objects? – Jan Wilamowski May 22 '21 at 08:16
  • @JanWilamowski Well, the 1st Person Controller has a collider that stops it walking through walls, right? So, I would like to extend/move the origin of the 1st Person Controllers collider to a cube in front of it so that it will not walk through a wall when the cube encounters a wall. Run the code to see what I mean. – SamTheProgrammer May 22 '21 at 09:55
  • 1
    I did run the code but there aren't any objects other than the floor. So when I add a cube, I will see the player cube intersect (clip into) it. Do you want to avoid that or just move the camera back to have a 3rd person view? – Jan Wilamowski May 23 '21 at 02:54
  • I want to make it so the cube is the player (3rd person view), I figured that 1st person controller would be good for it as I can't work out how to look around with the mouse without it. – SamTheProgrammer May 23 '21 at 08:17
  • To make sure you saw the previous comment, I'll tag you, @JanWilamowski – SamTheProgrammer May 23 '21 at 08:17
  • I added an answer - please let me know if I didn't understand your problem correctly. – Jan Wilamowski May 23 '21 at 12:58
  • I haven't quite run it in my game project (I am doing a ANN framework project currently), but it looks way simpler than I thought. I presume you also mean that I should parent the camera to the player. – SamTheProgrammer May 23 '21 at 13:46
  • yes, just as it's done in your code snippet. No changes other than the ones in my answer are needed. – Jan Wilamowski May 24 '21 at 03:56

1 Answers1

1

To show a 3rd person perspective, you can move the global camera back:

def to_first_person():
    camera.position = (0, 0, 0)

def to_third_person():
    camera.position = (0, 0, -3)

You could either do this once when loading the game or switch back and forth via keyboard inputs:

def input(key):
    if key == '1':
        to_first_person()
    if key == '3':
        to_third_person()
Jan Wilamowski
  • 3,308
  • 2
  • 10
  • 23