Creating a Player Node

Hello I am trying to make my player’s position relative to the node I attached it to.

Example: If I have a ship, then I would want to attach the player node to the ship so that the player moves with it.

The problem is I don’t know how to create a player node, CharacterControl can’t be attached to a node.



I hope you understand my question and are willing to help.



PS: I am pretty new to jME.

The problem is I don’t know how to create a player node.


[java]
Node playerNode = new Node("Player Node");
shipNode.attachChild(playerNode);
[/java]

:)

CharacterControl can’t be attached to a node.


Yes, it can :)

[java]
playerNode.addControl(myCharacterControl);
[/java]
@glaucomardano said:
[java]
Node playerNode = new Node("Player Node");
shipNode.attachChild(playerNode);
[/java]

:)



Yes, it can :)

[java]
playerNode.addControl(myCharacterControl);
[/java]

I think I tried that before but it didn't work.
Well, so can you tell me if I do that, when the shipNode moves will my playerNode move too?

Thanks



EDIT: Yep, I tried exactly that but the player seemed to be not affected by being attached to floor node :(
It was like it wasn't attached

I promise you that child nodes move when attached to parents. Do you have anything attached to this so-called “Player Node”?

Yeah, children move with their parents. It’s entirely the point.



If you see a child that isn’t moving with its parent then that parent isn’t really its parent anymore. You’ve attached it to something else (a spatial can only have one parent after all).

@pspeed said:
Yeah, children move with their parents. It's entirely the point.

If you see a child that isn't moving with its parent then that parent isn't really its parent anymore. You've attached it to something else (a spatial can only have one parent after all).

@sbook said:
I promise you that child nodes move when attached to parents. Do you have anything attached to this so-called "Player Node"?

I think it doesn't move because of the CharacterControl that has it's control...

Any physics control will move the spatial to the physics space location, thats the whole point :roll:

@normen said:
Any physics control will move the spatial to the physics space location, thats the whole point :roll:

I know so how can I make my player move relative to the node it's attached onto?
@ivandonat said:
I know so how can I make my player move relative to the node it's attached onto?

If you want to do so, don't use characters or attach the character to the node.
@normen said:
If you want to do so, don't use characters or attach the character to the node.

What do you mean?
Like, uhh, I create a box and then attach it to ship, and move it with setLocalTranslation instead of CharacterControl?

Yeah or you move the character elsewhere and translate the location to some spatial. Don’t think 1:1 world - computer, its always smoke and mirrors.

@normen said:
Don't think 1:1 world - computer, its always smoke and mirrors.

Uhh, what?
@ivandonat said:
Uhh, what?

You have a spaceship that moves in a physics space and want objects to attach to it. Thats the problem in real world but in almost all games you just completely switch the physics spaces when you board the ship, there is no "outside world" then anymore. If you see something moving outside its not actually in your physics space but happening in another one and just displayed on your screen. If you see a building crumble not every brck is simulated but some breaking parts are scripted. Things like that.
@normen said:
You have a spaceship that moves in a physics space and want objects to attach to it. Thats the problem in real world but in almost all games you just completely switch the physics spaces when you board the ship, there is no "outside world" then anymore. If you see something moving outside its not actually in your physics space but happening in another one and just displayed on your screen. If you see a building crumble not every brck is simulated but some breaking parts are scripted. Things like that.

Okay, well so many suggestions from people I don't know what to do
@ivandonat said:
Okay, well so many suggestions from people I don't know what to do

So this game is probably beyond your abilities still. Try something smaller for starters.
@normen said:
So this game is probably beyond your abilities still. Try something smaller for starters.

Just want to say a few things:
1) This is not a game, just want to see how can I do it because it's bothering me for a while
2) I am not new to programming, only to jME

The key is to think about what the result you are trying to achieve looks like on the screen and then try to ditch any assumptions you might have about how that would be done when you work out how to do it in the game.



Do you model a house by modelling every brick? When going into a vehicle do you really enter the vehicle? etc.



The two important things are what the player sees and how easily the computer is able to process the abstract model of the world in order to generate that…

@zarch said:
The key is to think about what the result you are trying to achieve looks like on the screen and then try to ditch any assumptions you might have about how that would be done when you work out how to do it in the game.

Do you model a house by modelling every brick? When going into a vehicle do you really enter the vehicle? etc.

The two important things are what the player sees and how easily the computer is able to process the abstract model of the world in order to generate that...

An example:
I am trying to achieve that you are inside a ship (a large room) that has consoles and stuff, and a big window where you see outside stuff. But when the ship moves you can still see through that window and you move along with the ship

I can also code but it doesn’t mean I can code shaders properly. I’d also have to write simple ones to get my feet wet first and not start out trying to top CryEngine… You can actually apply the physics to the local translation but to get correct results you need to have all objects attached to one node then, look at TestLocalPhysics, its an option for all physics controls. This way you can even have multiple spaces for multiple ships.

@ivandonat said:
An example:
I am trying to achieve that you are inside a ship (a large room) that has consoles and stuff, and a big window where you see outside stuff. But when the ship moves you can still see through that window and you move along with the ship


So the obvious approach is to do just that, create the ship, put the player inside, move the ship around.

But another approach is to have "ship space" in which the ship is moving and then "person space" in which your avatar is moving. These are both separate areas within the 3d world. I'd actually create a "ship inside" and "ship outside" node to hang all the relevant objects off.

There is a camera in ship space that moves along where the ship is and the viewport of that camera is then projected either onto the screen in ship space or onto a skybox surrounding the ship (if you have multiple screens/angles/etc).

Another option is to always have the ship placed at 0,0 and again put space outside on a node. When you "move the ship through space" in fact you move the space around the ship by translating that outside node.


Just think about what you want to achieve and how you want to achieve it. Also think about what rules you want where (for example physics, gravity, whatever) and how you are going to achieve that...

There is no generic right answer for any of this stuff - it all depends on exactly what you are trying to do what is better, and even then sometimes there are multiple good approaches.