-
Para tener cualquier presencia
física en la escena
-
un objeto de juego debe tener un
-
componente colisionador para
definir su forma física
-
y para interactuar con el
motor físico relevante.
-
Unity tiene 2 motores físicos.
-
Uno para 3D y otro para 2D.
-
Estos dos motores físicos
no interactúan entre si.
-
Para más información
sobre física y física 2D
-
por favor, vea la
información vinculada abajo.
-
Cuando se usa el motor físico 2D
-
un componente colisionador
2D debe ser usado.
-
Existen 4 componentes
colisionadores 2D para elegir.
-
El colisionador 2D circular,
-
el colisionador 2D caja,
-
el colisionador 2D poligonal
-
y el colisionador 2D de bordes.
-
Todos estos colisionadores
comparten muchas propiedades
-
ya que todos derivan del mismo
-
colisionador base 2D genérico.
-
Cada componente colisionador
2D sin embargo es
-
optimizado para una forma particular.
-
El colisionador 2D
circular funciona
-
con objetos circulares.
-
El colisionador 2D caja funciona
bien con objetos rectangulares.
-
El colisionador 2D poligonal funciona
-
mejor con formas complejas.
-
Y el colisionador 2D de bordes
funciona bien con superficies.
-
El colisionador de bordes y el
colisionador poligonal son muy similares.
-
Son creados por varios puntos, o vértices,
-
con bordes conectándolos.
-
La principal diferencia entre ellos
es que el colisionador poligonal
-
debe ser una forma
cerrada que cubre un área
-
Y el de bordes debe ser abierto,
-
definiendo un borde de
uno o más segmentos.
-
Un buen uso del colisionador de bordes
-
es hacer una única superficie sólida
-
en vez de una serie de colisionadores 2D
-
aún si varios sprites
son usados para crear
-
el aspecto visual de la superficie.
-
Cuando se compara todos
los colisionadores 2D
-
hay 2 propiedades
expuestas en el inspector
-
que todas comparten.
-
Is Trigger y Material.
-
Las otras propiedades
únicas son el definir
-
la forma de ese colisionador
2D particular.
-
La propiedad Is Trigger
establecerá al colisionador
-
para comportarse como
un colisionador disparador.
-
With normal 2D physics collisions
-
the 2D physics engine will prevent
-
2D colliders from passing through each other.
-
2D trigger colliders will not participate
-
in physical collisions and will send 2D
-
trigger messages rather than 2D collision messages.
-
These trigger messages can be used to
-
initiate new actions in the scene.
-
For more information on Is Trigger
-
and the messages sent by colliders
-
please see the information linked below.
-
The material property is a reference to the
-
physics material 2D being used by the collider 2D
-
and this can be none.
-
Physics materials define how colliders
-
will react when they collider
-
and define both the bounciness and
-
the friction of the collider's surface.
-
To make a bouncy ball or slippery ice covered platform
-
use a different physics material 2D
-
with each collider 2D.
-
For more information on physics material 2D
-
please see the information linked below.
-
To use a collider 2D it must be attached
-
to a game object.
-
One way of attaching a collider 2D component
-
is to use the Add Component button
-
and select Physics 2D
-
and select a Collider 2D Component.
-
For more information on game objects,
-
components and how to use them
-
please see the information linked below.
-
When a collider 2D component is attached
-
Unity will try to size the collider 2D to the sprite.
-
If the size and shape of the collider 2D
-
is undesirable then the shape can be edited by either
-
changing the values in the inspector
-
or changing the collider 2D itself in the scene view.
-
To edit a collider 2D in the scene view
-
hold down the shift key.
-
This will display handles on the 2D collider's
-
gizmo in the scene view.
-
These handles are drag-able.
-
In the case of the edge collider and the polygon collider
-
dragging an existing handle will move
-
the collider's vertex, and change the collider's shape
-
rather than resizing the collider.
-
By moving the cursor over an empty edge
-
on either the edge collider or the polygon collider
-
a new vertex can be created by clicking.
-
This is indicated by a new handle appearing
-
and the edge highlighting in green.
-
In the case of the edge collider and the polygon collider
-
holding the control key will allow a
-
vertex to the be deleted when clicked.
-
This is indicated by the handle
-
and the edge highlighting in red.
-
A game object does not need a rigidbodied
-
2D to use a collider 2D.
-
To participate in 2D collision and trigger events
-
however at least 1 of the game objects
-
involved must have a rigidbody 2D attached.
-
A common pattern for best performance
-
would be to attach collider 2D components
-
but not rigidbody components
-
to all of the static, or non-moving game objects
-
that need to interact with 2D physics.
-
And attach a collider 2D and a rigidbody 2D
-
to the dynamic, or moving, game object
-
that need to interact in the scene.
-
For more information on physics 2D
-
collider 2D, collisions and triggers
-
please see the information linked below.