Change Spawn Location

I’ve been having issues with altering the spawn location of an object in my application. I built walls around an area (that I want the player to be inside), but I cannot change the setPhysicsLocation of the object. Below is my code:



[java]

// Add a physics character to the world

physicsCharacter = new CharacterControl(new CapsuleCollisionShape(0.5f, 1.8f), .1f);

physicsCharacter.setPhysicsLocation(new Vector3f(0, 0, 0));

characterNode = new Node(“character node”);

Spatial model = assetManager.loadModel(“Models/Sinbad/Sinbad.mesh.xml”);

model.scale(0.25f);

characterNode.addControl(physicsCharacter);

getPhysicsSpace().add(physicsCharacter);

rootNode.attachChild(characterNode);

characterNode.attachChild(model);

[/java]



Note that I have the boxes spawn with a separate class. The boxes have RigidBodyControl(0), in case you were wondering.

what do you mean you cannot change it?

1 Like

I can modify the text, save it, etc. but when I run it I spawn in the exact same area. I’ve tried to greatly modify the location, but it hasn’t changed it either.

well you add a characterControl and set its location, the spatial will move along with the character from then on…

2 Likes

[java]

// Add a physics character to the world

<strong>physicsCharacter = new CharacterControl(new CapsuleCollisionShape(0.5f, 1.8f), .1f);

physicsCharacter.setPhysicsLocation(new Vector3f(0, 0, 0));</strong>

characterNode = new Node("character node");

Spatial model = assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");

model.scale(0.25f);

characterNode.addControl(physicsCharacter);

getPhysicsSpace().add(physicsCharacter);

rootNode.attachChild(characterNode);

characterNode.attachChild(model);

[/java]



Is that what you are referring to? If so, I had already implemented that. If I enter a different location for setPhysicsLocation it does not affect the spawn location of the player object.

Thats because you attach the control after you set the location, it will adapt the location of the spatial when attached.

2 Likes

Are you able to explain how I would go about doing so?



I’d also like to personally thank you for your help; you replied to my previous topic concerning the implementation of physics as well as this one. I really appreciate your help.

1 Like

Just add the control to the spatial before and then set the physicsLocation or set the translation of he spatial and then attach the control so that it adapts it.

1 Like

I feel horrible bumping this, but due to my lack of understanding I must plead for assistance once again. Is a fellow willing to write out what I must do in order to move the spawn location?

“add the control to the spatial before and then set the physicsLocation” :



characterNode.addControl(physicsCharacter); ← Add the control to the spatial

getPhysicsSpace().add(physicsCharacter);

physicsCharacter.setPhysicsLocation(new Vector3f(0, 0, 0)) ← Then set the physics location



OR



"set the translation of he spatial and then attach the control "



characterNode.setLocalTranslation(…) ← set the translation of he spatial

characterNode.addControl(physicsCharacter) ← Then attach the control

2 Likes