Move on any surface

I never did any stuff like this on server, but I can imagine how.

On the server side we need a part of the map’s mesh, it should be the place within reach on the surface. We can call it Navigation Mesh.

We need no materials, no textures, only the mesh. When moving on the surface, it means we have a start point and a target point on the mesh, then we need to calculate the path between two points.

This is just what the Recast Navigation did. The jme3-ai plugin did it, too.

On client side, we use mouse picking a target point on the map, and send it to server.

Server will decide if it’s an available place within reach. If it’s available, then calculate the path and move the player.

Client will receive the transform of the player and update the visual parts, such as position\rotation\animation.

1 Like

Here I would need a more “reactive” request to the server more the WASD keys. As well not a path finding but more a stay on the same height messured to the ground. So I would need kind a navmesh thing. Are there examples with such a mesh on the server?

In this usecase you need server side physics instead of navmesh.

Still we need the mesh, with which we can create a CollisonShape on server side. Add both player and the mesh’s collision shapes to bulletPhysics engine, then waiting for user input.

When user pressed WASD key, calculate the right ‘walking direction’ and send it to server.

On server side you can set player’s walking direction, then let bulletPhysics do the left stuff. Send player’s physical location to client per frame/tick.

On the client side, we update the player’s visiul parts with when received data from server.

I believe that there must be an example in sim-eth-es. It use bulletAppState as a System, processing Direction component and update Position component. But I cant find the link by now.

I made one in my own study project. I use zay-es in this game. InputState handles the WASD keys, CollisionState do the physics.

As I know, in real online game there should be physics engine on both clients and server. Client use physics engine to make player’s movement smother, the data received from server it used for validation. If the position on client side it not equal to the position on server side, player will “blink” to the server side position. It happens a lot when the latency is too high.

On server side, the terrain mesh is usually cut into small pieces. So the player’s collision shape can only do the math work with nearby meshes, that will make multiplayer online game server runs a little faster.

Someone talks about this problem before us

1 Like

Honestly I hoped to avoid a full fledge physic engine as I have simply a space fighter which should glide on every surface like sphere or cone or … :slight_smile:
But yeah in the end it is anyway some sort of physic system (I use sim-eth-es example as my base). And in my case I also need some mesh like thing to model this. So I’ll try to find a way. Thanks so far for your helpful and detailed input.

Whether you call it “terrain” or “collision mesh”… there must be some collidable thing on the server for the “physics” to operate on… even if it’s simple physics.

I added the gravity spheres to the sim-eth examples hoping to flesh a little of the collision and force system out but never got back to it. That would have been simple sphere-based collisions, though.

Anyway, often, the collision data on the server is not at all the same as the one the client sees as a “mesh”. Sometimes it is, though.

I did a search in our forum, and found something useful.

http://www.gabrielgambetta.com/fpm1.html

https://developer.valvesoftware.com/wiki/Latency_Compensating_Methods_in_Client/Server_In-game_Protocol_Design_and_Optimization

Ok so I still have the problem of the “how” but at least I have now the direction. I guess I’ll start with a “sphere map” of my actually 2D game which just hapen to take place on a Sphere :slight_smile:
I think to move one a sphere does not need any complicated physic (I do not even need jump as space ships don’t do that :wink:) Most probably I stay with spherical maps just to keep things as simple as possible.
I wonder if somebody did something like Mario Galaxy which is similar to what I want. I think some quaternion magic’s

Thanks a lot. But to have bullet engine for what I want seems a bit overkill and it all looks complicated. Btw I use @pspeed interpolation algo from sim-eth-es which do a pretty good job so I guess having a physic on the server should do it (or at least it seems to work pretty fine with the simple physic engine I have in place). At the moment my surface is just flat so it is in my case purly 2D from the perspective of movement.

One idea I have at the moment is that when I simply define a center (0,0,0) and place the space ship for example to (0, 100, 0) and define a radius 100. Now when ever I move in the x, z plane I have to do a correction, so that the distance to the center is always the same as well I have slighlt adjust where my nose points to. Not sure, but this sounds the easiest way. I just need to make my SimplePhysicSystem be able to do the corrections. Or do I maybe overlook something? I guess the problem is that I do not stay in the x, z plane :frowning:
Btw. by now I changed the sim-eth-es in a way that I can see the ship top down in a bird view. The sphere would make the game more attractive and you also could see your enemy a bit better because of the sphereical earth like view…

I did the same in my game, but I kept it in planar 2d. I also considered adding spherical game worlds, but decided it was too advanced to dive into right away. I’ll watch your posts to keep tabs on the progress if you share it :slight_smile:

Also this may be of some help.

I plan to share :slight_smile: at least outlines of the solution if I find any good one (formulas or so). I hope you do so as well :wink:

Cool, I guess that is what I need! I’ll study that in more detail. Thanks.

Also, looking at those videos of the game, I sense something… a presence I’ve not felt since… ©

Maybe it is not the case, but all the surfaces I’ve seen there so far don’t seem to be really arbitrary, they’re regular… so it might be that the key is some smart coordinate system transform… in this case what would be passed to client is just type of that used (i.e.: “this is a cylinder map”), and, having cylinder math model in it, client builds surface and transforms coordinates accordingly to do visualization, and to process user input… thus it might be that on server all that’d be enough to store is just x, y coordinates plus transform type… my own math is too poor to say for sure, though

Edit: those additions in bold

yeah exactly also my thought, these are all regular surfaces and some smart math.
I played that geometry war and it somehow feels good, that’s why I want to try to have similar maps (maybe in the end it will just be a shpere, but that is better than nothing, further more that way I have a natural limit of the battle ground :slight_smile: )
And for top down games that transform also makes that you can look farther… somehow.

I think I start with sphere, I found something in a unity 3D forum http://answers.unity3d.com/questions/41050/how-can-i-make-movement-on-a-sphere.html maybe that is the one.

There is a similar video for this type of game.

Is there also code snipped laying around for this? looks like what I’m looking for :slight_smile:

The shapes in Geometry Wars 3 look suspiciously well suited for distance fields…
http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm

Distance fields give you the distance from an arbitrary point to the nearest object without ray casting.
Might be worth a look.

2 Likes

It took me some time to get the idea. Looks pretty simple you have one single origin and then you have a point in space and the formula gives you the distance to the surface. So you have the direction and the length, only need to adjust the facing of the ship. Cool. I will give it a try.

I’m so close, but I’m not able to get the orientation corrected. This is my adjusted Body.class from sim-eth.es

package ch.artificials.bg.sim;

import com.simsilica.es.EntityId;
import com.simsilica.mathd.*;

import ch.artificials.bg.es.Position;

public class Body {

    public final EntityId bodyId;

    public Vec3d pos = new Vec3d();
    public Vec3d velocity = new Vec3d();
    public Vec3d acceleration = new Vec3d();
    public double radius = 1;
    public double invMass = 1;
    public AaBBox bounds = new AaBBox(radius);

    public Quatd orientation = new Quatd();
    public volatile DriverControl driver;

    // XXX: experiment
    public Vec3d altPos = new Vec3d();
    public Quatd altOrientation = new Quatd();

    public Body(EntityId bodyId) {
        this.bodyId = bodyId;
    }

    public Body(EntityId bodyId, double x, double y, double z) {
        this.bodyId = bodyId;
        pos.set(x, y, z);
    }

    public void setPosition(Position pos) {
        this.pos.set(pos.getLocation());
        this.orientation.set(pos.getFacing());
    }

    public void integrate(double stepTime) {
        // Integrate velocity
        velocity.addScaledVectorLocal(acceleration, stepTime);

        // Integrate position
        pos.addScaledVectorLocal(velocity, stepTime);
        
        // XXX Trial
        pos.normalizeLocal();
        pos.multLocal(30);
    }
}

The XXX Trial is my change. Radius of my sphere is 30 for the moment. I put the ship initial on (0, 30, 0). So now it runs on one half of a sphere, but because the orientation is not adjusted it get’s slower and slower till it reaches the half of the sphere. Makes sense, because the thrust is in the direction of the body. I think I only need to adjust the x-axis rotation. I wanted to measure the angle between before and after the pos update, I did a toVector3f().clone() on entrance and on exit and then did oldPos.angleBettween(newPos), but the result is always 0.

EDIT: Of course I have to follow this local x axis rotation on client I also do not yet, because that client orientation is the one I would need in the end that thrust points “around” the sphere.

Something I miss here, but I don’t know what exactly. In case somebody sees my mistake I’m happy to hear and learn.