java - libgdx ashley ecs framework - Should I use MovementSystem with PhysicsSystem? -
if movementsystem
behavior this.
public class movementsystem extends intervaliteratingsystem { private vector2 temp = new vector2(); public movementsystem() { super(family.all(transformcomponent.class, movementcomponent.class).get(), constants.time_step); } @override protected void processentity(entity entity) { transformcomponent transform = mappers.transform.get(entity); movementcomponent movement = mappers.movement.get(entity); vector2 acceleration = temp.set(movement.accel).scl(0.5f); movement.velocity.add(acceleration); vector2 acceleratedvelocity = temp.set(movement.velocity).scl(0.5f); transform.position.add(acceleratedvelocity); } }
while on physicssystem
behavior.
public class physicssystem extends intervaliteratingsystem { @override protected void processentity(entity entity) { physicscomponent physics = mappers.physics.get(entity); transformcomponent transform = mappers.transform.get(entity); sizecomponent size = mappers.size.get(entity); transform.position.set(physics.body.getpositon()); transform.rotation = physics.body.getangle(); } } playersystem { public void updatemovement(entity entity) { playercomponent player = mappers.player.get(entity); physicscomponent physics = mapper.physics.get(entity); movementcomponent movement = mapper.movement.get(entity); float velocity = player.move_velocity; switch(movement.state) { case up: movement.velocity.set(0, velocity) break; case down: movement.velocity.set(0, -velocity) break; case left: movement.velocity.set(-velocity, 0) break; case right: movement.velocity.set(velocity, 0) break; } physics.body.setlinearvelocity(movement.velocity); } }
objectives
- to update body position (this can done using
physicssystem
) - to update texture position (this can done using
movementsystem
)
problems
- i've use both systems
physicssystem
overriding or updatingtransformcomponent
datasmovementsystem
incrementingtransformcomponent
position, usingmovementcomponent
velocity , acceleration.- when both systems used texture confused because of
physicssystem
,movementsystem
positioning.
question
do think i'm doing right? it's behavior need revise fit objectives?
Comments
Post a Comment