Collider
Beschreibung
Diese Komponente erstellt einen Physik-Collider für eine Entität.
ColliderShape
Typ | Beschreibung |
---|---|
Box | Box |
Sphäre | Sphäre |
Flugzeug | Flugzeug |
Kapsel | Kapsel |
Kegel | Kegel |
Zylinder | Zylinder |
Eigenschaften
Name | Typ | Standard | Beschreibung |
---|---|---|---|
Form (erforderlich) | ecs.ColliderShape | ecs.ColliderShape.Box | Unterstützte Typen sind in ecs.ColliderShape verfügbar |
width | Nummer | 0 | Breite von Kasten- oder Flächenformen. |
height | Nummer | 0 | Höhe von Kasten-, Ebenen-, Kapsel-, Kegel- oder Zylinderformen. |
Tiefe | Nummer | 0 | Tiefe der Boxform. |
radius | Nummer | 0 | Radius von Kugel-, Kapsel-, Kegel- oder Zylinderformen. |
Masse | Nummer | 0 | Masse der Entität. Lassen Sie 0 stehen, um statisch zu sein |
eventOnly | boolean | false | Soll das Objekt nur Kollisionsereignisse versenden und nicht physisch reagieren |
gravityFactory | Nummer | 1 | Faktor für die Skalierung der Weltgravitation |
lockXAxis | boolean | false | Deaktiviert die Drehung auf der X-Achse |
lockYAxis | boolean | false | Deaktiviert die Drehung um die Y-Achse |
lockZAxis | boolean | false | Deaktiviert die Drehung auf der Z-Achse |
Reibung | Nummer | 0.5 | Das Ausmaß der Kontaktreibung an der Einheit |
Rückerstattung | Nummer | 0 | Die Sprunghaftigkeit der Entität |
linearDämpfung | Nummer | 0 | Der Luftwiderstand während der Bewegung |
angularDamping | Nummer | 0 | Der Luftwiderstand beim Drehen |
spinningFriction | Nummer | 0 | Der Betrag der Reibung an der Einheit während des Drehens |
Funktionen
Get
Returns a read-only reference.
Example
ecs.Collider.get(world, component.eid)
Set
Ensures the component exists on the entity, then assigns the (optional) data to the component.
Example
ecs.Collider.set(world, component.eid, {
shape: 'ecs.ColliderShape.Box',
width: 0,
height: 0,
depth: 0,
radius: 0,
mass: 0,
eventOnly: false,
gravityFactory: 1,
lockXAxis: false,
lockYAxis: false,
lockZAxis: false,
friction: 0.5,
restitution: 0,
linearDamping: 0,
angularDamping: 0,
spinningFriction: 0
})
Mutate
Perform an update to the component within a callback function. Return true
to indicate no changes made.
Example
ecs.Collider.mutate(world, component.eid, (cursor) => {
cursor.mass = 5;
cursor.friction = 0.8;
return false;
})
Remove
Removes the component from the entity.
Example
ecs.Collider.remove(world, component.eid)
Has
Returns true
if the component is present on the entity.
Example
ecs.Collider.has(world, component.eid)
Reset
Adds, or resets the component to its default state.
Example
ecs.Collider.reset(world, component.eid)
Advanced Functions
Cursor
Returns a mutable reference. Cursors are reused so only one cursor for each component can exist at a time.
Example
ecs.Collider.cursor(world, component.eid)
Acquire
Same behavior as cursor, but commit must be called after the cursor is done being used.
Example
ecs.Collider.acquire(world, component.eid)
Commit
Called after acquire. An optional third argument determines whether the cursor was mutated or not.
Example
ecs.Collider.commit(world, component.eid)
ecs.Collider.commit(world, component.eid, false)
Dirty
Mark the entity as having been mutated. Only needed in a specific case where systems are mutating data.
Example
ecs.Collider.dirty(world, component.eid)