Entity
</> ursina.entity
Class Variables
.rotation_directions
default: (-1, -1, 1)
.default_shader
default: unlit_shader
.default_values
default: {'parent': scene, 'name': 'entity', 'enabled': Tru...
Initialization
copy Entity (
add_to_scene_entities=True,
enabled =True,
parent =scene,
position =Vec3(0 , 0 , 0 ),
rotation =Vec3(0 , 0 , 0 ),
scale =Vec3(1 , 1 , 1 ),
model ='' ,
origin =Vec3(0 , 0 , 0 ),
shader =Default,
color =color.white,
texture ='' ,
texture_scale =Vec2 .one,
texture_offset=Vec2 .zero,
collider =None,
eternal=False
)
Attributes
.name
default: camel_to_snake(self.__class__.__name__)
.ignore
default: False
if True, will not try to run code.
.ignore_paused
default: False
if True, will still run when application is paused. useful when making a pause menu for example.
default: False
.add_to_scene_entities
default: add_to_scene_entities
set to False to be ignored by the engine, but still get rendered.
.scripts
default: []
add with add_script(class_instance). will assign an 'entity' variable to the script.
.animations
default: []
.hovered
default: False
will return True if mouse hovers entity.
.parent
default: parent
default parent is scene, which means it's in 3d space. to use UI space, set the parent to camera.ui instead.
.shader
default: shader if shader is not Default else __class__.def...
.line_definition
default: None
returns a Traceback(filename, lineno, function, code_context, index).
.line_definition
default: caller
.code_context
default: caller.code_context[0]
.name
default: self.code_context.split(' = ')[0].strip().replace(...
Getters
types
get all class names including those this inherits from.
X
shortcut for int(entity.x)
Y
shortcut for int(entity.y)
Z
shortcut for int(entity.z)
forward
get forward direction.
back
get backwards direction.
right
get right direction.
left
get left direction.
up
get up direction.
down
get down direction.
screen_position
get screen position(ui space) from world space.
model_bounds
bounds
loose_children
attributes
attribute names. used by duplicate().
Properties
enabled
disabled entities will not be visible nor run code.
model
set model with model='model_name' (without file type extension)
color
example: Entity(model='cube', color=hsv(30,1,.5))
eternal
eternal entities does not get destroyed on scene.clear()
double_sided
render_queue
for custom sorting in case of conflict. To sort things in 2d, set .z instead of using this.
parent
loose_parent
world_parent
change the parent, but keep position, rotation and scale
visible
visible_self
collider
set to 'box'/'sphere'/'capsule'/'mesh' for auto fitted collider.
collision
toggle collision without changing collider.
on_click
origin
origin_x
Convenience property for setting first element of origin
origin_y
Convenience property for setting second element of origin. Example: Entity(model='cube', origin_y=-.5) # The origin point of the cube is now at the bottom instead of the center.
origin_z
Convenience property for setting second element of origin
world_position
world_x
world_y
world_z
position
right, up, forward. can also set self.x, self.y, self.z
x
y
z
world_rotation
world_rotation_x
world_rotation_y
world_rotation_z
rotation
can also set self.rotation_x, self.rotation_y, self.rotation_z
rotation_x
rotation_y
rotation_z
quaternion
world_scale
world_scale_x
world_scale_y
world_scale_z
scale
can also set self.scale_x, self.scale_y, self.scale_z
scale_x
scale_y
scale_z
shader
material
a way to set shader, texture, texture_scale, texture_offset and shader inputs in one go
texture
set model with texture='texture_name'. requires a model to be set beforehand.
texture_scale
how many times the texture should repeat, eg. texture_scale=(8,8).
texture_offset
tileset_size
tile_coordinate
alpha
shortcut for setting color's transparency/opacity
always_on_top
unlit
set to True to ignore light and not cast shadows
billboard
set to True to make this Entity always face the camera.
wireframe
set to True to render model as wireframe
flipped_faces
children
Methods
enable()
same as .enabled = True
disable()
same as .enabled = False
copy get_shader_input(name=None)
copy set_shader_input(name=None, value=None)
get_position()
copy get_position(relative_to=scene)
get position relative to on other Entity. In most cases, use .position instead.
set_position()
copy set_position(value=None, relative_to=scene)
set position relative to on other Entity. In most cases, use .position instead.
rotate()
copy rotate(value=None, relative_to=None)
rotate around local axis.
add_script()
copy add_script(class_instance=None)
combine()
copy combine(analyze=False, auto_destroy =True, ignore =[], ignore_disabled=True, include_normals =False)
look_at()
copy look_at(target=None, axis=Vec3 .forward)
look_in_direction()
copy look_in_direction(direction=None, forward_axis=Vec3 .forward)
look_at_2d()
copy look_at_2 d(target=None, axis='z' )
Example
copy from ursina import *
app = Ursina()
start_point = Draggable(model ='circle' , color =color.orange, scale =.0 2 5 , position =(-0 ,-0 ))
end_point = Draggable(model ='circle' , color =color.orange, scale =.0 2 5 , position =(.2 ,.1 ))
line = Entity (parent =camera.ui, model ='line' , origin_x =-.5 ) # set origin_x = -.5 o it starts at the left and not the middle.
def update():
line.position = start_point.position
line.look_at_2 d(end_point) # could also ise .look_at() (3 d) for this.
line.rotation_z -= 9 0 # look_at_2 d assumes up as forward, so offset by -9 0 degrees.
line.scale_x = distance_2 d(start_point, end_point)
app.run()
look_at_xy()
copy look_at_xy(target=None)
look_at_xz()
copy look_at_xz(target=None)
has_ancestor()
copy has_ancestor(possible_ancestor=None)
get_descendants()
copy get_descendants(include_disabled=True)
recursively get all descendants (children, grandchildren, and so on)
has_disabled_ancestor()
get_changes()
copy get_changes(target_class=None)
returns a dict of all the changes
animate()
copy animate(
name=None,
value=None,
duration=0 .1 ,
delay =0 ,
curve =curve.in_expo,
loop=False,
resolution=None,
interrupt='kill' ,
time_step=None,
unscaled=False,
ignore_paused=None,
auto_play =True,
auto_destroy =True,
getattr_function=None,
setattr_function=None,
lerp_function=lerp
)
animate_position()
copy animate_position(value=None, duration=0 .1 )
animate_rotation()
copy animate_rotation(value=None, duration=0 .1 )
animate_scale()
copy animate_scale(value=None, duration=0 .1 )
copy animate_shader_input(name=None, value=None)
shake()
copy shake(
duration=0 .2 ,
magnitude=1 ,
speed=0 .0 5 ,
direction=(1 , 1 ),
delay =0 ,
attr_name='position' ,
interrupt='finish' ,
unscaled=False,
ignore_paused=True
)
animate_color()
copy animate_color(value=None, duration=0 .1 , interrupt='finish' , unscaled=False)
fade_out()
copy fade_out(value=0 , duration=0 .5 , unscaled=False)
fade_in()
copy fade_in(value=1 , duration=0 .5 )
blink()
copy blink(color =ursina.color.white, shader =unlit_shader, duration=0 .1 )
intersects()
copy intersects(traverse_target=scene, ignore: list=None, debug=False)