Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - Minigame

Pages: [1] 2
Support / how can I smooth my automated camera system??
« on: May 01, 2015, 05:13:44 am »
Ok so I've perfected the movement system for my game, but it uses 8 directions for player rotations (A* paths) and my camera seems to be EXTREMELY twitchy / jerky because of that..

My question is how can I smooth the camera system? Here's the code I'm using to make the camera follow the player.

Code: [Select]

public void update() {
                // I think the following 3 lines is what makes the camera seem to jerk or twitch, since the player rotates in 1 of 8 directions.. and the camera snaps to the player
camera.align(abstractHuman.getModel()); // align the camera with the player

camera.rotateCameraX((float) Math.toRadians(30)); // angle
camera.moveCamera(Camera.CAMERA_MOVEOUT, 90); // zoom

I've tried timers for camera updating but they only cut down on the amount of twitchy/jerky camera movements. How can I make something smoother?

Projects / Yet Another jPCT RPG
« on: April 27, 2015, 09:43:55 pm »

Latest Build - May 2015

I've implemented a fair amount of detail into the game. Everything from smart movement and game controls, to a world editor tool and item support. The latest build is essentially just the foundation for an RPG, and does not represent an actual game... Once the code base is "finished" I will most likely invest into better assets.

Older Build - May 2015

First Prototype - February 2015

Support / Bots Animating With Player?
« on: April 26, 2015, 08:04:19 am »
It's been quite a while since I've posted, or even programmed! So hello again jPCT community.

Anyways, I picked up a project that was inactive for quite some time and tonight I've implemented bots which are meant to wonder the game world and do random things... as expected.

So the problem is that all bots animate with the player? Example: When I walk, the bots stay idle but perform the movement animation. The bots are meant to be their own entities, and not do as the player does. I believe the problem has something to do with the method I store and clone the model...

Here is some code:

snippet from model storage class
Code: [Select]

public ObjectCache() {
this.male = generateMale();
this.female = generateFemale();

private Object3D generateMale() {
Object3D male = Loader.loadMD2("./res/md2/male.md2", .10f / 2);
textureManager.addTexture("male", new Texture("./res/md2/male.jpg"));
textureManager.addTexture("male-mask", new Texture("./res/md2/male.png"));
this.maleBaseTexture = new TextureInfo(textureManager.getTextureID("male"));
maleBaseTexture.add(textureManager.getTextureID("male-mask"), TextureInfo.MODE_ADD);
male.rotateY((float) Math.PI * 1.5f); // Properly rotate the MD2 model
male.compile(true); // Compile dynamic object
return male;

private Object3D generateFemale() {
Object3D female = Loader.loadMD2("./res/md2/female.md2", .091f / 2);
textureManager.addTexture("female", new Texture("./res/md2/female.jpg"));
textureManager.addTexture("female-mask", new Texture("./res/md2/female.png"));
this.femaleBaseTexture = new TextureInfo(textureManager.getTextureID("female"));
femaleBaseTexture.add(textureManager.getTextureID("female-mask"), TextureInfo.MODE_ADD);
female.rotateY((float) Math.PI * 1.5f); // Properly rotate the MD2 model
female.compile(true); // Compile dynamic object
return female;
        // note "male" and "female" are models which are loaded and storaged once.
public Object3D getMob(boolean gender, final float[][] colors) {
Object3D obj = new Object3D(gender ? male : female, true);
obj.shareCompiledData(gender ? male : female);
GLSLShader shader = new GLSLShader(Loader.loadTextFile("./res/md2/player.vert"), Loader.loadTextFile("./res/md2/player.frag")) {
public void setCurrentObject3D(Object3D obj) {
setUniform("colorMul0", colors[0]);
setUniform("colorMul1", colors[1]);
setUniform("colorMul2", colors[2]);
setStaticUniform("map0", 0);
setStaticUniform("map1", 1);
return obj;
Code: [Select]
public class Player {

private final World world;

// the model which represents our player
private Object3D model;

// position stuff
private SimpleVector cachedPosition = new SimpleVector(0, 0, 0);
private SimpleVector nextPosition = null;

// animation stuff
private float animationFrame = 0;
private int animationId = 1;

// name above head stuff
private String username = "Player Name";
private SimpleVector aboveHeadVector;
private int nameLength = 0;

// path finder stuff
private PathFinder pathFinder;
private Path path;
private long lastAutoWalTranslation = 0L;
private int currentStepIndex = 0;
private int pathTranslations = 0;
private Tile targetTile;

public Player(final World world, Terrain terrain) { = world;
this.pathFinder = new AStarPathFinder(terrain, 64 * 64, true);

public void setUsername(GLFont font, String username) {
this.username = username;
nameLength = font.getStringBounds(username).width / 2;

public void update() {
autoWalk(); // process auto walk
translate(); // do smooth translations
animate(); // animate

* Translates the model in 3D space.
public void translate(boolean smooth, float x, float y, float z) {
if (!smooth) {
* Teleport the player to the destination.
this.model.translate(x, y, z);
this.cachedPosition = model.getTransformedCenter();
} else {
* Set the next position variable so that we can begin the auto walk
* process using a series of smaller, "smooth", translations.
this.nextPosition = new SimpleVector(x, y, z);

private void translate() {
if (nextPosition != null) {
* Check if we're within distance of the target destination.
if (MathUtil.inRange(1.5f, false, cachedPosition, nextPosition)) {
* If so, let's reset the nextPosition variable so that the player
* stops auto walking.
nextPosition = null;
* Rotate towards next position.
SimpleVector s = new SimpleVector(getX(), 0, getZ());
SimpleVector t = new SimpleVector(nextPosition.x, 0, nextPosition.z);
SimpleVector direction = new SimpleVector(t.calcSub(s)).normalize();
Matrix rotationMatrix = new Matrix(direction.getRotationMatrix());

* Translate forward towards the destination.
SimpleVector forward = model.getZAxis();
forward.scalarMul(.36f); // speed
SimpleVector moveVector = new SimpleVector(forward);
this.cachedPosition = model.getTransformedCenter();

* Here we're just using jPCT's md2 animation system.
private void animate() {
animationFrame += 0.02f;
if (animationFrame > 1) {
animationFrame -= 1;
animationId = path != null ? 2 : 1; // walking or idle
if (model != null) {
model.animate(animationFrame, animationId);

* Builds a new model instance.
public void build(boolean male, float[][] colors) {
if (model != null) {
cachedPosition = model.getTransformedCenter();
model = null;
this.model = ObjectCache.getInstance().getMob(male, colors);;

* Renders the users name above their head.
* @note: This MUST be called after rendering the jPCT world.
public void renderAboveHeadText(GLFont font, Camera camera, FrameBuffer frameBuffer) {
try {
aboveHeadVector = Interact2D.project3D2D(camera, frameBuffer, model.getTransformedCenter());
if (aboveHeadVector != null && username != "" && username.length() > 0) {
font.drawString(frameBuffer, username, (int) aboveHeadVector.x - nameLength, (int) aboveHeadVector.y - 42, Color.WHITE);
} catch (Exception ignore) {
// This happens because the vector returned null - and cannot be avoided.
// Just ignore it.

* Generates a new A* path to the supplied destination.
public void generatePath(int snapped_x, int snapped_z) {
if (path != null) {
path = pathFinder.findPath(model, getX(), getZ(), snapped_x, snapped_z);
if (path == null) {
System.err.println("Cannot generate path!");
currentStepIndex = 0;
pathTranslations = path.getLength();
setTargetTile(snapped_x, snapped_z);

* Resets all of the auto walk related variables.
private void resetPath() {
nextPosition = null;
path = null;
currentStepIndex = 0;
pathTranslations = 0;

* If the player has a path to follow, let's loop through
* the steps and set the smooth translation request.
private void autoWalk() {
if (path != null && lastAutoWalTranslation < (System.nanoTime() / 1000000) - 35) {
lastAutoWalTranslation = System.nanoTime() / 1000000;
if (currentStepIndex == pathTranslations) {
translate(true, path.getX(currentStepIndex), 0, path.getY(currentStepIndex));
//setTargetTile(path.getX(currentStepIndex), path.getY(currentStepIndex));

private void setTargetTile(int x, int z) {
// update target tile
if (targetTile != null) {
int targetX = x / 6;
int targetZ = z / 6;
targetTile = new Tile(targetX * 6, targetZ * 6);
targetTile.translate(0, -1, 0);

* Returns the players current position.
public SimpleVector getTransformedCenter() {
return model == null ? cachedPosition : model.getTransformedCenter();

* Returns the model instance.
public Object3D getModel() {
return model;

public Object3D getTargetTile() {
return targetTile;

* Returns the players X coordinate.
public int getX() {
return (int) cachedPosition.x;

* Returns the players Z coordinate.
public int getZ() {
return (int) cachedPosition.z;


I hope I've provided enough code for somebody to point out the technical issue with my application. As mentioned when I tell the local player to walk, the bots with the same gender will animate with it.. ex: all male bots will animate with my male player when the male player walks

Support / 3D -> 2D mouse coords?
« on: January 24, 2015, 10:48:53 am »
I've got the 2D -> 3D mouse coordinates concept down, but how can I reverse that? My goal is to set up a system where I can click on an entity, and a simple options box will be rendered in 2D space.

Here's a microsoft paint where red X = mouse position and the white box is what I want to accomplish..

Projects / Multi Player Sandbox RPG [video & source]
« on: January 20, 2015, 12:05:13 am »
I was just about to delete this project from my eclipse directory and decided I would upload a copy for anybody who might be interested in using it.
Keep in mind this was my first (functional) mutli player 3D game so there is room for improvement, but at least the code is readable ;) I just posted this exact same thread on JGO

The video is probably not the same as the current build, so here's a screen shot I took which would be 100% accurate:

Download link:

How to host & join
First you'll need to open the project using Eclipse IDE, then refer to this image:

After you run the client you will be prompted for a username and hostname in the Eclipse console.

You can either type the desired name then press enter, or just press enter for a random username.
The same goes for hostname, where no hostname = localhost, etc. etc. You get the point.

Projects / jPCT A* Path Finding Example (Open Source)
« on: December 13, 2014, 11:58:00 pm »
This is a hacked together test application to show off a VERY BASIC A* Path Finding implementation.
There is room for a better implementation... but for those having trouble with the first step, this is a great starting point  :P

Credits go to jPCT forum user Bryan, and a bit for myself as well

Uppit links are quite infested with fake download links, so I copied the direct file URL, but I don't know if it will work:

If that link does not work, here is the generated URL (be weary uppit is full of fake download links)

Support / Realistic Water Translations?
« on: December 02, 2014, 07:12:19 am »
I want some type of "realistic water flow".. Is this possible with jPCT? If so, where do I even begin. I've never done anything like it before.


Projects / AeonRPG 3D | open source | high detail
« on: November 23, 2014, 09:31:56 pm »
Ok so I've hoarded this for a while, mostly due to the insane amount of $ invested into asset creation.. But times change, and I'm ready to let it go, and move on.  ;D

Anyways do as you want. Everything is public domain. IT would be nice however, to if I don't see this renamed to Whatever RPG and publishing it without any content modifications.. - 27.5 MB

Open the client source folder, and run Engine as a Java Application..

* Press F to toggle first person or third person camera mode
* Hold WASD (or ARROE KEYS) to move around / rotate
* Use your mouse and click buttons on the UI to do some stuff.. (interfaces aren't finished)
* Press I to spawn a random ground item
* Press ENTER when near an entity, to interact (ex. talk to npc, pick up item)
* Press ESCAPE to terminate the application

* There might be more, I forget, it has been a little while since I've worked with this project
other than adding some notes and testing things before the release.

Private Message me if you need any help (The natives and jars are in /file_storage/java/)

If you want to add props, lights, or mob spawns to the game, it's pretty simple. The data loads from .cfg files which can be found in /file_storage/config/

Here is an example from npcs.cfg to show the easy to use syntax.. <entity id> <x> <y> <z> // comment
Code: [Select]
// lumber ridge
2, 9872.726, 90.9, 10147.348 // wizard
1, 10867.035, 90.9, 10961.692 // archer
0, 9039.265, 90.9, 10227.28 // warrior

In you can change a few things which will effect performance and game detail.
If you want a higher frame rate, go into -> int requestedFPS = XXX;

There are some hot keys which will teleport you to different areas of the game world, and if you press CTRL you will walk with incredible speed (all of this was for development)

Support / advice before implementation
« on: August 29, 2014, 01:51:23 pm »
I'm rendering a multi player scene with jPCT and netty. I want to create a character design interface, but I'm not sure what the best way to swap a model on the fly..

Player entity is either set to male or female upon initialization. But it needs to be changable after init too... but it's not, yet.

class Player extends Object3D { ...
    super(Primitives.getPyramide(4.2f, 2f)); ...

    // what is the most efficient way to add an overlaying model and keep the pyramid from rendering or using necessary resources

Support / Resizable seems a little buggy
« on: July 01, 2014, 08:54:08 pm »
This code is ready for execution in the main loop, but when I resize the frame the mouse pointer turns into a scroll pointer (2 ended arrow) and it seems like in-game / terrain clicking is completely whack. Am I doing something wrong?

            if (Display.wasResized()) {
               frameBuffer.resize(Display.getWidth(), Display.getHeight());
               mouseYOffset = frameBuffer.getOutputHeight();
                                // all other rendering stuff is under here

Oh.. and here's a screen shot of what happens on the login menu when the frame is resized (everything becomes distorted and placed / scaled awkwardly)

Support / Best way to remove objects safely / building walls
« on: May 12, 2014, 04:11:03 am »
What is the best way to remove a specific object (or list of objects) from a jpct world, safely and efficiently? I am rendering a multi player scene but having issues with removing only some models upon logout.. (ex: static props will not need removed)

..and another question.. How can I create a proper 2 sided wall? I've been using rotated planes with wooden textures to create buildings using code. The walls only render when looked at from a certain angle with the camera.

Support / sortOffset problem
« on: April 11, 2013, 02:29:18 pm »
Pic says it all. I don't fully understand how the sortOffset works, but I have played with it a lot and the result is always the same.

Edit: What can I do to determine a proper offset for the z-Sorting? I've read the docs, and the current value is -500k

Support / translation and distance
« on: March 10, 2013, 11:49:54 am »
I have been trying to figure out how to determine the distance between vector A and vector B, then use the result to determine if it is within a certain range in world space.
I have experimented and tried many various attempts for some time but..  ???

Here's an example of code representing what my overall goal would be (1 of many failed attempts)
Code: [Select]
float distanceToDestination = localPlayer.getTransformedCenter().calcSub(dest).length(); // XXX
if (distanceToDestination <= 100) {
// Here, I would translate the local player in my game <distanceToDestination> world units.

I've tried a lot of different solutions and I'm not really that great with these type of mathematics so any help is very much appreciated

Support / Camera follow help
« on: February 13, 2013, 06:28:04 am »
I have a click to walk system in my game app, and previously used a method that just followed the player from behind, but now am trying to base things around a user controlled POV that uses arrow key input (360 degree left / right rotation, and 45 degrees from the ground, or 15 degrees above ground level).
The user controlled camera works fine, but I can't get it to follow the player. I know about Camera.CAMERA_MOVE*, but it goes off screen from being called each tick. Is there a function to determine the distance from the player object, so that I could force a MOVEIN / MOVEOUT appropriately maybe?

Support / Tile Blending
« on: February 01, 2013, 10:48:56 pm »
I have been toying with jPCT for over a year now, and have created a lightweight "game engine" that I use for something I call my 3D digital world project, and a few utilities.

Here is a preview of the map editor utility, and the million dollar question is: how can I blend the tiles?

I've looked at the terrain release, which features some sort of blending, but I wasn't able to get what I needed out of it.
A nice explanation on how to approach blending tiles would be excellent, because I feel it would take my project to a new level (in terms of visual appearance).


Pages: [1] 2