Read serial port and use in the game

Good evening

I like to read my serial port (wich contais a hardware plugged int with an accelerometer system to move sensors) and use this data ( movements ) to move my actor.  Is something very simple I need, but I don't know this engine enough and I'm having some problems with it.

Can someone give me a help???

thanks a lot.

jME doesn't handle tasks like reading from a serial port. This is something that is to be done with a seperate library.

You can try searching online on how to read data from a serial port in java:

I already did it.My program read the serial port and integrate the acceleration already. My only question is about make this coordinates move the element in the game , like if I was pressing a key.

thanks for you reply.  :smiley:

If you use jMEPhysics, try addForce(),

if not, you have to do this manually through setLocalTranslation()…

please can u give me a simply example how should I do it

that's what I have in mind:

my pattern velocity is 50 ( when I read this value, the actor stays freeze)

read the values , example 60 soon my actor needs to move right.

I try to forge the KeyPressed, but have no success. For your consideration I take the simple game example available here and try to do it, but I can't make my actor moves.

I know I'm boring, but I need to do it for my university last project until now all the rest is finished, but I made my moves just in 2d mode using native libraries and jpanels, but I need to do it using jMonkey.

thanks 4 your help.

you have one field in your class:

private float veloctiy;

Than you have one method:

public void update(float tpf) {
   float input = // read in your acceleration
   float acceleration = input - 50; // subtract your pattern velocity
   velocity += acceleration;
   setLocalTranslation(getLocalTranslation().add(velocity, 0, 0));

Than, in your simpleGame, you:

private Spatial actor;
public void simpleUpdate(float tpf) {

Now everything clear? Hope that helps...