Two questions

Hi Guys,

I am new to jmonkey and i am trying to develop a continuous runner( subway surfer) like game. I want to have 2-3 maps ( like a long horizontal plane with some static objects int it, like trees) My character will run on it.

a) The issue i am facing is that i want to know when my character is at the end of one plane(map) so i will load next one. So it will continue infinite one after one. Also i need to know the co-ords of the second end of map so i can create some dynamic objects like trains so they will come towards the player. Find the pic below for the explanation. So my question is how can i get the co-ords (start and end).

b) I am trying to move the player in another lane by simple keyboard key listener.

ublic void onAction(String binding, boolean value, float tpf) {
if (binding.equals(“Left”)) {
left = value;
} else if (binding.equals(“Right”)) {…

I found that , the key listener will act 100 times in between the key pressed and released. How can i improve it so that char will move left only once when i press left arrow key.

a ) There’s probably a few ways to accomplish this. You could check the bounds of the player, and see if he is in the BoundingBox of the plane (this might or may not work, on a completely flat plane, and there will be other issues if your player can jump higher than it etc). Depending on the geometry of the plane, if its a straight track like that then you can use the extents of the plane, and simply check the world translation of the player, and the world translation of the plane + extents.

b ) In your onAction () method, don’t assign a variable which will be used in the update loop, instead do the action directly in there; then it will only happen once

1 Like

Thanks wesley, i will try that . I want the coming cars objects to start from either current plane start or next plane start thats why i want the start co-ords. Lets say plane have 4 vertices in 2d space

A B

C D

So will world translations give me the A B co-ords?( My player will be running from CD -> AB.

It depends where the plane origin is. If its in the center, then the start of the first plane, relative to the parent node, will be: (assuming an x y axis like in that pic)

[java]plane.getLocalTranslation ().getY ().subtract (((BoundingBox)plane.getWorldBound ()).getYExtent());[/java]

the next one will be
[java]plane1.getLocalTranslation ().getY ().subtract (((BoundingBox)plane1.getWorldBound ()).getYExtent());[/java]

etc

<cite>@wezrule said:</cite> a ) There's probably a few ways to accomplish this. You could check the bounds of the player, and see if he is in the BoundingBox of the plane (this might or may not work, on a completely flat plane, and there will be other issues if your player can jump higher than it etc). Depending on the geometry of the plane, if its a straight track like that then you can use the extents of the plane, and simply check the world translation of the player, and the world translation of the plane + extents.

b ) In your onAction () method, don’t assign a variable which will be used in the update loop, instead do the action directly in there; then it will only happen once

Second issue solved, thanks for that. I am testing the 1st issue right now.
I am thinking of another issue here. I am planning to implement some dynamic objects( like car, bus or a piller) in each scene, some will be static some with speed. Now i will need to detect collision with the player,

The way i am thinking is creating classes for all objects and call a method to initialize some objects random ally for the current plane. I would like to check collision inside that class( rather than checking in update loop from character(player)) . My question here is will it work? or i have to extend the SimpleGame class for each of my object class?

SimpleGame class? You can use BoundingVolume collision detection (check in update loop), or if using physics, you can use Physics Collision events

I think i can do this with the help of controls :slight_smile:

One another thing when the update loop of control will get called? at the start of the simpleapplication update loop or end of the loop?

<cite>@aniket0 said:</cite> I think i can do this with the help of controls :)

One another thing when the update loop of control will get called? at the start of the simpleapplication update loop or end of the loop?

Relative to what?

Both the issues are solved and we can close this thread.

Meanwhile , i have used custom controls and the concept is awesome and works like charm. Thanks to the developers for implementing it.
@pspeed that was regards for the collision detection i was planning in control update. I have player and some random objects in my game , these random objects will be classes and i have associated a custom control to these class constructor so i can detect the collision of that object with player in the control update loop.
It have made my main update loop pretty small.