Skip to content

Commit

Permalink
fixed shadows and character shape
Browse files Browse the repository at this point in the history
  • Loading branch information
codex128 committed Aug 1, 2023
1 parent 080f96b commit b5da222
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
52 changes: 27 additions & 25 deletions src/codex/jumpstart/ESGameState.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,7 @@ protected void init(Application app) {
if (spatial.getName().equals("start")) {
startLocation.set(spatial.getWorldTranslation());
}
}

// create player entity
EntityId player = ed.createEntity();
ed.setComponents(player,
new Visual(),
new Animation(),
new Physics(),
new CharacterShape(1f, 5f, 150f),
new WalkDirection(),
new ViewDirection(),
new WalkSpeed(0f),
new TargetSpeed(0f),
new Accelleration(.1f, .1f),
new LookAtWalk(true),
new Hand());
// model
var spatial = assetManager.loadModel("Models/characters/YBot.j3o");
spatial.setLocalScale(.01f);
spatial.setCullHint(Spatial.CullHint.Never); // since this spatial will presumably always be in focus
scene.attachChild(spatial);
// registering
getState(VisualState.class).link(player, spatial);
singleplayer = new SinglePlayerState(player);
getStateManager().attach(singleplayer);
}

var gi = new AmbientLight(ColorRGBA.DarkGray);
scene.addLight(gi);
Expand Down Expand Up @@ -140,6 +116,32 @@ public void done(LightProbe result) {
//updater.addShadowRenderer(dlsr);
skyControl.setEnabled(true);


// create player entity
EntityId player = ed.createEntity();
ed.setComponents(player,
new Visual(),
new Animation(),
new Physics(),
new CharacterShape(.4f, 2f, 150f),
new WalkDirection(),
new ViewDirection(),
new WalkSpeed(0f),
//new TargetSpeed(0f),
//new Accelleration(.1f, .1f),
new LookAtWalk(true),
new Hand());
// model
var spatial = assetManager.loadModel("Models/characters/YBot.j3o");
spatial.setLocalScale(.01f);
spatial.setCullHint(Spatial.CullHint.Never); // since this spatial will presumably always be in focus
spatial.setShadowMode(RenderQueue.ShadowMode.Cast);
scene.attachChild(spatial);
// registering
getState(VisualState.class).link(player, spatial);
singleplayer = new SinglePlayerState(player);
getStateManager().attach(singleplayer);

}
@Override
protected void cleanup(Application app) {
Expand Down
2 changes: 1 addition & 1 deletion src/codex/jumpstart/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void simpleInitApp() {

bulletapp = new BulletAppState();
bulletapp.setDebugViewPorts(viewPort);
bulletapp.setDebugEnabled(true);
//bulletapp.setDebugEnabled(true);
stateManager.attach(bulletapp);

stateManager.attach(new EntityAppState());
Expand Down
9 changes: 6 additions & 3 deletions src/codex/jumpstart/es/system/SinglePlayerState.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.simsilica.es.EntityComponent;
import com.simsilica.es.EntityId;
import com.simsilica.lemur.GuiGlobals;
Expand Down Expand Up @@ -136,14 +135,14 @@ public void update(float tpf) {
currentDir.nlerp(desiredDir, .1f);
set(new WalkDirection(currentDir.mult(Vector3f.UNIT_Z)));
}
set(new WalkSpeed(Math.max(FastMath.abs(inputdirection.z), FastMath.abs(inputdirection.x))*1f));
set(new WalkSpeed(Math.max(FastMath.abs(inputdirection.z), FastMath.abs(inputdirection.x))*getWalkSpeed()));
}
else if (aimShifting) {
if (inputdirection.z != 0 || inputdirection.x != 0) {
Quaternion rotation = new Quaternion().lookAt(get(ViewDirection.class).getDirection(), Vector3f.UNIT_Y);
set(new WalkDirection(rotation.getRotationColumn(2).multLocal(inputdirection.z).addLocal(rotation.getRotationColumn(0).multLocal(-inputdirection.x)).normalizeLocal()));
}
set(new WalkSpeed(Math.max(FastMath.abs(inputdirection.z), FastMath.abs(inputdirection.x))*1f));
set(new WalkSpeed(Math.max(FastMath.abs(inputdirection.z), FastMath.abs(inputdirection.x))*getWalkSpeed()));
}
if (shoulder.isEnabled()) {
shoulder.setSubjectTranslation(control.getRigidBody().getPhysicsLocation());
Expand Down Expand Up @@ -281,6 +280,10 @@ private <T extends EntityComponent> T get(Class<T> type) {
private void set(EntityComponent component) {
ed.setComponent(player, component);
}

private float getWalkSpeed() {
return FastMath.interpolateLinear(speedfactor, 2f, 10f);
}
private boolean isAlive() {
return !layerControl.isActive("death");
}
Expand Down

0 comments on commit b5da222

Please sign in to comment.