Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
Hi ! I want to code in AS3 my own fps gameplay but I have some problems : I understand Camera has no rotation (this is little strange...). So, for looking around I use setCameraTarget(). I use a circle radius, for example : cx = stage.width/2 cy = stage.height/2 targetx = cx - Math.sin(angle)*radius targetz = cy + Math.cos(angle)*radius simpleAPI.setCameraTarget(cam,targetx,targety,targetz) It works fine but now I don't understand for the correct translations. My code : if (leftKey ) {camera_position.x++} if (rightKey ) {camera_position.x--} if (upKey ) {camera_position.z--} if (downKey ) {camera_position.z++} setSceneNodePosition(cam,camera_position.x,camera_position.y,camera_position.z) OK it works but only if my target is in front of me. When I turn my look, the camera rotation is the same, so translations are false. (if I turn my look at 180° upKey/dowkKey are reversed) My question : What about coding for good translations ? My method is good ? Thanks a lot, Cyril |
||||
|
It should work like this: Take the target point of the camera and substract it from the camera position, and you get the vector the camera looks into: dx = cameratarget.X - camera_position.X; To make sure the vector has the correct length, make it so long as how much you want to move, like this: var lengthToMove:Number =2.0f; Now, you could move the position of the camera by that vector, and that's it: camera_position.x += dx; hope this helps! Update: Ah, I see, that's only what you need to the up and down key. (down it's minus then). For left and right, it gets a bit more complicated in 3D, I guess. You need to use the cross product with the upvector or something similar then, to find the correct left and right direction. |
||||
|
Yes, Thank you very much, you help me. But the camera target move too ? How ? In fact, camera fps is a 3rd person camera with an unvisible target object, isn't it ? |
||||
|
Yes, that's right. The target is in that case always locked to the object you are looking to. In case of a FPS camera, you need to move the target the same way as you move the camera position. |
|