I know, I know… see “scenegraph for dummies”… already done that, please bear with me
I’ve made a parent Node, attached a child Geometry to it and attached a CharacterControl to the parent Node.
Then I want to rotate the parent Node. The method getWorldRotation() shows that the parent Node is rotated, but on the screen I don’t see the child rotating…
Constructor:
CharacterControl control; AnimChannel channel; public AnimControl animControl; TerrainQuad terrain; public Node spatial=new Node(); public Spatial model; Quaternion q = new Quaternion(); float speedFact; GameLogicHook gameLogic; public RedMonkey(float x, float y,float z, TerrainQuad terrain, Spatial model, GameLogicHook gameLogic, float yTranslation) { tags.add("Monkey"); this.terrain=terrain; this.model=model; this.model.setLocalTranslation(0, yTranslation, 0); this.spatial.move(x,y,z); this.position=spatial.getLocalTranslation(); this.spatial.attachChild(model); this.gameLogic=gameLogic; }
Rotation:
public void setBehaviorTree(AssetManager assetManager, String tree) { BehaviorTreeParser<RedMonkey> parser = new BehaviorTreeParser<RedMonkey>(BehaviorTreeParser.DEBUG_NONE); behaviorTree = parser.parse((String) (assetManager.loadAsset(tree)), this); } public boolean notSleeping(String anim) { return !anim.equals(channel.getAnimationName()); } public void move(Vector3f dir) { control.setWalkDirection(dir); Vector3f norM = terrain.getNormal(new Vector2f(spatial.getWorldTranslation().x, spatial.getWorldTranslation().z)); norM = norM.cross(dir).cross(norM); q.lookAt(norM, Vector3f.UNIT_Y); spatial.setLocalRotation(q); System.out.println("Spatial rotation"+spatial.getWorldRotation()); } public boolean lookingAround(ArrayList<String> tags) { for (RMItem sensedItem : getSense().scan()) {
When the Spatial is linked to a physics object, it cannot be transformed normally. You have to use the physics functions for those operations.
1 Like
Makes sense. Let’s do yet another intermediary node…
.setViewDirection should do the Trick
1 Like
Well… more or less. With this code I get endless spinning:
Quaternion q;
q.lookAt(norM, Vector3f.UNIT_Y);
control.setViewDirection(q.mult(control.getViewDirection()));
How should I fix it?
A quaternion is a rotation, and you probablly apply it in every single frame? resulting in a spinning.
Empire_Phoenix:
resulting in a spinning.
I know, I want to do the CharacterControl equivalent of this:
spatial.setLocalRotation(q);
Don’t you already have an simple lookat point? I mean there has to be a reason for what you want to lookat.
Other than that, simply use x = sin Rotation around y axis (phi) and z = cos phi.
BUt i guess there is something built in like createLookAt.
Take a look at like the chasercams and stuff
1 Like
ah ok
new Vector3f(0,0,1) → forward
q.lookAt(whereever)
q.multLoca(forward)
→ forward in q rotated space now
setViewDir(forward) → set the rotated forward dir
1 Like