Description
I am busy rewriting ursina.prefabs.platformer_controller_2d
In the update function, you can see it uses boxcast 3 times (the last time doesn't matter as much) .
I've refactored it to this, we have a boxcast for the sides, and we have a boxcast for the bottom.
def update(self):
verticalRay = boxcast(
self.position+Vec3(self.velocity * time.dt * self.walk_speed,self.scale_y/2,0),
# self.position+Vec3(sefl,self.scale_y/2,0),
direction=Vec3(self.velocity,0,0),
distance=abs(self.scale_x/2),
ignore=(self,),
traverse_target=self.traverse_target,
thickness=(self.scale_x*.99, self.scale_y*.9),
debug=True
)
bottomRay = boxcast(
self.world_position+Vec3(0,.1,0),
self.down,
distance=max(.15, self.air_time * self.gravity),
ignore=(self, ),
traverse_target=self.traverse_target,
thickness=self.scale_x*.9,
debug=True
)
if not verticalRay.hit:
self.x += self.velocity * time.dt * self.walk_speed
if bottomRay.hit:
if not self.grounded:
self.land()
self.grounded = True
self.y = bottomRay.world_point[1]
return
else:
self.grounded = False
if not self.grounded and not self.jumping:
self.y -= min(self.air_time * self.gravity, bottomRay.distance-.1)
self.air_time += time.dt*4 * self.gravity
As you can see, the debug is true. However, it will only show one at a time, depending on which one I instantiate last (it takes preference to the last one).
There's also weird behavior with the bottom cast when the vertical cast is in, even though they are unrelated. I'm linking a video to explain.
Screen.Recording.-.Made.with.FlexClip.online-video-cutter.com.webm
In this video, you can see that it does this weird thing where it bounces up and down, when I comment the boxcast that has to do with the sides (not the bottom), it then stops doing it. Also, as you can see, it only shows one debug indicator at a time.
I'm using vscode on windows.