Search in sources :

Example 1 with RaySensor

use of ilargia.egdx.logicbricks.component.sensor.RaySensor in project Entitas-Java by Rubentxu.

the class RaySensorSystem method query.

@Override
protected boolean query(SensorEntity sensorEntity, float deltaTime) {
    RaySensor sensor = sensorEntity.getRaySensor();
    sensor.rayContactList.clear();
    sensor.collisionSignal = false;
    Link link = sensorEntity.getLink();
    float angle = sensor.axis2D.ordinal() * 90.0f;
    GameEntity originEntity = Indexed.getInteractiveEntity(link.ownerEntity);
    Vector2 point1 = originEntity.getRigidBody().body.getPosition();
    Vector2 point2 = point1.cpy().add(new Vector2((float) MathUtils.cosDeg(angle), MathUtils.sinDeg(angle)).scl(sensor.range));
    physics.rayCast((fixture, point, normal, fraction) -> reportRayFixture(sensor, fixture), point1, point2);
    return sensor.collisionSignal;
}
Also used : RaySensor(ilargia.egdx.logicbricks.component.sensor.RaySensor) GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) Vector2(com.badlogic.gdx.math.Vector2) Link(ilargia.egdx.logicbricks.component.sensor.Link)

Example 2 with RaySensor

use of ilargia.egdx.logicbricks.component.sensor.RaySensor in project Entitas-Java by Rubentxu.

the class SensorEntity method replaceRaySensor.

public SensorEntity replaceRaySensor(String targetTag, Axis2D axis2D, float range, boolean xRayMode) {
    RaySensor component = (RaySensor) recoverComponent(SensorComponentsLookup.RaySensor);
    if (component == null) {
        component = new RaySensor(targetTag, axis2D, range, xRayMode);
    } else {
        component.targetTag = targetTag;
        component.axis2D = axis2D;
        component.range = range;
        component.xRayMode = xRayMode;
        component.collisionSignal = false;
        component.rayContactList = EntitasCollections.createSet(Integer.class);
    }
    replaceComponent(SensorComponentsLookup.RaySensor, component);
    return this;
}
Also used : RaySensor(ilargia.egdx.logicbricks.component.sensor.RaySensor)

Example 3 with RaySensor

use of ilargia.egdx.logicbricks.component.sensor.RaySensor in project Entitas-Java by Rubentxu.

the class SensorEntity method addRaySensor.

public SensorEntity addRaySensor(String targetTag, Axis2D axis2D, float range, boolean xRayMode) {
    RaySensor component = (RaySensor) recoverComponent(SensorComponentsLookup.RaySensor);
    if (component == null) {
        component = new RaySensor(targetTag, axis2D, range, xRayMode);
    } else {
        component.targetTag = targetTag;
        component.axis2D = axis2D;
        component.range = range;
        component.xRayMode = xRayMode;
        component.collisionSignal = false;
        component.rayContactList = EntitasCollections.createSet(Integer.class);
    }
    addComponent(SensorComponentsLookup.RaySensor, component);
    return this;
}
Also used : RaySensor(ilargia.egdx.logicbricks.component.sensor.RaySensor)

Aggregations

RaySensor (ilargia.egdx.logicbricks.component.sensor.RaySensor)3 Vector2 (com.badlogic.gdx.math.Vector2)1 Link (ilargia.egdx.logicbricks.component.sensor.Link)1 GameEntity (ilargia.egdx.logicbricks.gen.game.GameEntity)1