How to use the ursina.hit_info.HitInfo function in ursina

To help you get started, we’ve selected a few ursina examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pokepetter / ursina / ursina / mouse.py View on Github external
def find_collision(self):
        self.collisions = list()
        self.collision = None
        if not self.raycast or self._pq.get_num_entries() == 0:
            self.unhover_everything_not_hit()
            return False

        self._pq.sortEntries()

        for entry in self._pq.getEntries():
            for entity in scene.entities:
                if entry.getIntoNodePath().parent == entity and entity.collision:
                    if entity.collision:
                        hit = HitInfo(
                            hit = entry.collided(),
                            entity = entity,
                            distance = distance(entry.getSurfacePoint(scene), camera.getPos()),
                            point = entry.getSurfacePoint(entity),
                            world_point = entry.getSurfacePoint(scene),
                            normal = entry.getSurfaceNormal(entity),
                            world_normal = entry.getSurfaceNormal(scene),
                            )
                        self.collisions.append(hit)
                        break

        if self.collisions:
            self.collision = self.collisions[0]
            self.hovered_entity = self.collision.entity
            if not self.hovered_entity.hovered:
                self.hovered_entity.hovered = True
github pokepetter / ursina / ursina / raycaster.py View on Github external
return self.hit

        self.collision = self.entries[0]
        nP = self.collision.get_into_node_path().parent
        point = self.collision.get_surface_point(nP)
        # point = Vec3(point[0], point[2], point[1])
        point = Vec3(point[0], point[1], point[2])
        world_point = self.collision.get_surface_point(render)
        # world_point = Vec3(world_point[0], world_point[2], world_point[1])
        world_point = Vec3(world_point[0], world_point[1], world_point[2])
        hit_dist = self.distance(self.world_position, world_point)

        if nP.name.endswith('.egg'):
            nP = nP.parent

        self.hit = HitInfo(hit=True)
        for e in scene.entities:
            if e == nP:
                # print('cast nP to Entity')
                self.hit.entity = e

        self.hit.point = point
        self.hit.world_point = world_point
        self.hit.distance = hit_dist

        normal = self.collision.get_surface_normal(self.collision.get_into_node_path().parent)
        # self.hit.normal = (normal[0], normal[2], normal[1])
        self.hit.normal = (normal[0], normal[1], normal[2])

        normal = self.collision.get_surface_normal(render)
        # self.hit.world_normal = (normal[0], normal[2], normal[1])
        self.hit.world_normal = (normal[0], normal[1], normal[2])
github pokepetter / ursina / ursina / raycaster.py View on Github external
if debug and ray.hit:
                    d = Entity(model='cube', origin_z=-.5, position=pos, scale=(.02, .02, distance), ignore=True)
                    d.look_at(pos + Vec3(direction))
                    debugs.append(d)
                    # print(pos, hit.point)
                    if ray.hit and ray.distance > 0:
                        d.scale_z = ray.distance
                        d.color = color.green

        from ursina import destroy
        # [destroy(e, 1/60) for e in debugs]

        rays.sort(key=lambda x : x.distance)
        closest = rays[0]

        return HitInfo(
            hit = sum([int(e.hit) for e in rays]) > 0,
            entity = closest.entity,
            point = closest.point,
            world_point = closest.world_point,
            distance = closest.distance,
            normal = closest.normal,
            world_normal = closest.world_normal,

            hits = [e.hit for e in rays],
            entities = list(set([e.entity for e in rays])), # get unique entities hit
            )
github pokepetter / ursina / ursina / raycaster.py View on Github external
self.hit.entity = e

        self.hit.point = point
        self.hit.world_point = world_point
        self.hit.distance = hit_dist

        normal = self.collision.get_surface_normal(self.collision.get_into_node_path().parent)
        # self.hit.normal = (normal[0], normal[2], normal[1])
        self.hit.normal = (normal[0], normal[1], normal[2])

        normal = self.collision.get_surface_normal(render)
        # self.hit.world_normal = (normal[0], normal[2], normal[1])
        self.hit.world_normal = (normal[0], normal[1], normal[2])
        return self.hit

        self.hit = HitInfo(hit=False)
        return self.hit
github pokepetter / ursina / ursina / raycaster.py View on Github external
self._picker.traverse(traverse_target)

        if self._pq.get_num_entries() == 0:
            self.hit = HitInfo(hit=False)
            return self.hit

        ignore += tuple([e for e in scene.entities if not e.collision])

        self._pq.sort_entries()
        self.entries = [        # filter out ignored entities
            e for e in self._pq.getEntries()
            if e.get_into_node_path().parent not in ignore
            ]

        if len(self.entries) == 0:
            self.hit = HitInfo(hit=False)
            return self.hit

        self.collision = self.entries[0]
        nP = self.collision.get_into_node_path().parent
        point = self.collision.get_surface_point(nP)
        # point = Vec3(point[0], point[2], point[1])
        point = Vec3(point[0], point[1], point[2])
        world_point = self.collision.get_surface_point(render)
        # world_point = Vec3(world_point[0], world_point[2], world_point[1])
        world_point = Vec3(world_point[0], world_point[1], world_point[2])
        hit_dist = self.distance(self.world_position, world_point)

        if nP.name.endswith('.egg'):
            nP = nP.parent

        self.hit = HitInfo(hit=True)