www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: coersum on October 19, 2012, 06:25:48 pm

Title: Moving an object3D around
Post by: coersum on October 19, 2012, 06:25:48 pm
Hi,

I know this has been talked about before and I read quite a bit about in forum but nothing seems to work.
What I have is:

1. I load my serialized objects (ground and quickly made robot, just a meshes with textures) and everything works fine
Code: [Select]
mesh_plaza = Loader.loadSerializedObject(res.openRawResource(R.raw.plaza4s));
mesh_plaza.setScale(30);
mesh_plaza.setTexture("text_plaza");
mesh_plaza.translate(0, -20, 0);
world.addObject(mesh_plaza);
mesh_plaza.strip();

mesh_robot = Loader.loadSerializedObject(res.openRawResource(R.raw.robots));
mesh_robot.setScale(20);
mesh_robot.setTexture("text_robot");
mesh_robot.translate(0, -35, 0);
mesh_robot.setName("airob");
mesh_robot.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
world.addObject(mesh_robot);
mesh_robot.strip();

2. In onTouchEvent I set moveSpeed and touchTurn variables (i use a dpad I made for it, so moveSpeed is between -2 and +2, 0 being center of my directional-pad)

3. In the onDrawFrame for turning: (that works GREAT, the robot turns on the it's Y axis)
Code: [Select]
if (touchTurn != 0) {
//world.getCamera().rotateY(touchTurn);
mesh_robot.rotateY(touchTurn);
}
4. Still in onDrawFrame, for moving I tried quite a few things and found in forum that using the object's getZAxis would give me its current directionto which then I just add to z (or x depending on how it was modeled):
Code: [Select]
if (moveSpeed != 0) {
SimpleVector robot_turn = mesh_robot.getZAxis();
mesh_robot.translate(robot_turn.x, robot_turn.y, robot_turn.z+moveSpeed);
}
But this gives some very weird results. First, without turning, the robot will go back and forth (his front is initially positioned on the Z axis) but once I start turning all hell breaks loose.
he will often just move sidewise-forward not only in one direction.

Any help or hint would be awesome.
Thank you
PS: next I am going to try to get the camera to follow, get the robot to not go through walls, add gravity so the robot can jump etc...so much to learn.
Title: Re: Moving an object3D around
Post by: EgonOlsen on October 19, 2012, 08:44:09 pm
It doesn't work that way. You have to multiply the robot_turn vector with moveSpeed instead of adding it to the z-axis.
Title: Re: Moving an object3D around
Post by: coersum on October 21, 2012, 08:49:19 pm
Could you help me on how to do that by chance ?  just can't get anything to work. Been trying to find examples of 3d objects being moved around, with physics etc, I just can't find much sadly.
Title: Re: Moving an object3D around
Post by: EgonOlsen on October 21, 2012, 10:35:09 pm
Something like this should actually work:
Code: [Select]
if (moveSpeed != 0) {
SimpleVector robotTurn = meshRobot.getZAxis();
        robotTurn.scalarMul(moveSpeed);
meshRobot.translate(robotTurn);
}
Title: Re: Moving an object3D around
Post by: coersum on October 22, 2012, 12:22:03 am
thank you so much!! I think I actually tried that but I was having so much trouble going through the doc (not the doc's fault), that I might have had something else added to that which made it not work. Got the Chase-Camera to work finding info on this thread in case someone is looking for it: http://www.jpct.net/forum2/index.php/topic,2588.msg19139.html#msg19139