Physics location character

How set Physics Location ?

[java]
public void load_AnotherCharacter(){
BetterCharacterControl character_2 = new BetterCharacterControl(2f,6f, 1f);
Node model_2 = (Node) assetManager.loadModel(“Models/Oto/Oto.mesh.xml”);
model_2.addControl(character_2);
bulletAppState.getPhysicsSpace().add(character_2);
rootNode.attachChild(model_2);
}
[/java]

[java]character_2.warp(new Vector3f(x, y, z);[/java]

I don’t understand becouse when I push run the oto character jump and half-bust collapse in the floor :(((((
this is the simple code :

[java]

import CharacterControl.PhysicsTestHelper;
import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.animation.AnimEventListener;
import com.jme3.animation.LoopMode;
import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.PhysicsSpace;
import com.jme3.bullet.collision.shapes.BoxCollisionShape;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.control.BetterCharacterControl;
import com.jme3.bullet.control.GhostControl;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.light.AmbientLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.control.Control;

public class Main extends SimpleApplication{

private BulletAppState bulletAppState;


public static void main(String args[]){
	Main main = new Main();
	main.start();
}




@Override
public void simpleInitApp() {
	 //activation phisycs in the scene by addyng a bulletUpState
    activatPhisycs();

//initialize the scene and give it the meshCollisionShape
//in this sample, helper class creates a flat floor and drops some cubes and spheres on it.
initializeScene();
//turn on the light
lightOn();

    load_AnotherCharacter();
    
}

public void activatPhisycs(){
	   bulletAppState = new BulletAppState();
	   stateManager.attach(bulletAppState);
}


public void initializeScene(){
	PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
}

public void lightOn(){
	AmbientLight light = new AmbientLight();
	  light.setColor(ColorRGBA.White.mult(2));
	  rootNode.addLight(light);
}

public void load_AnotherCharacter(){
	BetterCharacterControl character_2 = new BetterCharacterControl(2f,4f, 2f);
	Node model_2 = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    model_2.addControl(character_2);
    bulletAppState.getPhysicsSpace().add(character_2);
    rootNode.attachChild(model_2);
    character_2.warp(new Vector3f(0, 0, 0));
}

}
[/java]

try adding the following line before you warp the player:

[java]character_2.setApplyPhysicsLocal(true);[/java]

I do but nothing ! :(( half bust is under the floor

oh. sorry. attach your spatial to the model_2 node before you attach model_2 to the rootnode.

1 Like

what spatial? Im a beginner write please …

I can’t spoon feed you, you need to learn what you are doing and have the determination and ability to figure things out for yourself. Its a steep curve, but if you really want it, you will get there. Personally I don’t think i’m the brightest spark in the bonfire, but I am a very determined character. You need at least one or the other to succeed. If you have both, well you’re in a better position than I am :slight_smile:

Don’t cast the oto mesh to a node. It is a spatial:
[java]Node model_2 = (Node) assetManager.loadModel(“Models/Oto/Oto.mesh.xml”);[/java]

That is the spatial i was referring to in my previous post.

1 Like

thanks I do this, but nothing :

“attach your spatial to the model_2 node before you attach model_2 to the rootnode.”

[java]

public void load_AnotherCharacter(){
	BetterCharacterControl character_2 = new BetterCharacterControl(2f,4f, 2f);
	Spatial otoModel = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
	bulletAppState.getPhysicsSpace().add(character_2);
    Node  model_2 = new Node();
    character_2.setApplyPhysicsLocal(true);
    model_2.addControl(character_2);
    model_2.attachChild(otoModel);
    rootNode.attachChild(model_2);
	character_2.warp(new Vector3f(0, 0, 0));
}

[/java]

sigh…

You have attached the model to the physics space before you built your character fully. You need to do things in order.

But you are able to help me?
I wanna the same result of this:

[java]
public void loadCharacter(){
//set the collision shape
CapsuleCollisionShape capsule = new CapsuleCollisionShape(3f, 4f);
//set the character capsule collision Shape
character = new CharacterControl(capsule, 0.05f);
character.setJumpSpeed(10f);
//load xml.mesh model
model = (Node) assetManager.loadModel(“Models/Oto/Oto.mesh.xml”);
//add control in model
model.addControl(character);
bulletAppState.getPhysicsSpace().add(character);
rootNode.attachChild(model);
character.setPhysicsLocation(new Vector3f(0,0,0));
}

[/java]
NOthing good work !!
You have understand what is the problem here ?

[java]

public void load_AnotherCharacter(){
		BetterCharacterControl character_2 = new BetterCharacterControl(2f,4f, 2f);
		Spatial otoModel = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
        Node  model_2 = new Node();
        character_2.setApplyPhysicsLocal(true);
        character_2.warp(new Vector3f(0, 0, 0));
        model_2.addControl(character_2);
        model_2.attachChild(otoModel);
        bulletAppState.getPhysicsSpace().add(character_2);
        rootNode.attachChild(model_2);
	}

[/java]

help me :frowning:

Working through the tutorials will help you far more than we can.