Libgdx New Api Move Instance Model along angle;
Okay, so with the new API for Libgdx available, I decided to jump into 3D.
All was well until I ran into what I thought was a basic problem.... So,
here it is.
The Idea is to move a Instance model that has been rotated along that
current angle/degree. Here is the code i intended on doing it with. Keep
in mind that this code has been died up and re-written quite a few times
so it aint perfect, I know.
if(isSentient && controllable){
if(walk){
if(Gdx.input.isKeyPressed(Keys.UP)){
pos = getPosition();
instance.transform.idt();
pos.z += Gdx.graphics.getDeltaTime() * Math.sin(rotation);
pos.x += Gdx.graphics.getDeltaTime() * Math.cos(rotation);
instance.transform.setToTranslation(pos);
}if(Gdx.input.isKeyPressed(Keys.DOWN)){
pos = getPosition();
instance.transform.idt();
pos.z -= Gdx.graphics.getDeltaTime() * Math.sin(1);
pos.x -= Gdx.graphics.getDeltaTime() * Math.cos(1);
instance.transform.setToTranslation(pos);
}if(Gdx.input.isKeyPressed(Keys.LEFT)){
rotation+=0.1;
pos = getPosition();
instance.transform.idt();
instance.transform.setToRotation(Vector3.Y,
rotation).trn(pos);
}if(Gdx.input.isKeyPressed(Keys.RIGHT)){
rotation-=0.1;
pos = getPosition();
instance.transform.idt();
instance.transform.setToRotation(Vector3.Y,rotation).trn(pos);
}
}
}
No comments:
Post a Comment