List of usage examples for com.badlogic.gdx.math CatmullRomSpline locate
@Override public float locate(T v)
From source file:releasethekraken.GameWorld.java
/** * Gets the target position that a sea creature should move towards, based on * where the sea creature currently is. At the end of the path, it will be * the last point on the path.//from w ww . ja v a 2 s.c om * @param entity The sea creature * @return The position the sea creature should move towards */ public Vector2 getPathTargetPos(EntitySeaCreature entity) { if (entity.getCurrentPath() == null) //Immediately return if there is no path to follow return entity.getPos(); //TODO: The target position doesn't seem to be that great CatmullRomSpline smoothPath = entity.getCurrentPath().getSmoothPath(); Vector2 targetPos = new Vector2(); float pathProgress = smoothPath.locate(entity.getPos()); if (pathProgress >= 0.9F) //Randomly choose a next path. TODO: Allow for choosing { //Gdx.app.log(entity.toString(), "At the end of the path! ****************************************************************"); SeaCreaturePath nextPath = entity.getCurrentPath().getNextPaths().random(); if (nextPath != null) { entity.setCurrentPath(nextPath); return getPathTargetPos(entity); } } smoothPath.valueAt(targetPos, pathProgress); return targetPos; }