Fosef Posted May 5, 2010 Share Posted May 5, 2010 Trying to create a third person camera, not sure if I'm going in the right path code wise or not. I've been going off the code from Third person camera - ball game example by Aggror Not sure what I'm doing wrong...If I had to guess, its something with the Pivot? In the end I actually want to have an animated player model, not a ball, but figure the ball is good starting point, unless the physics of a ball are actually the issue? #1 Am I on the right path, or should I be using the controller somehow? (I can't get the tutorial code to do anything, no movement at all) #2 The camera doesn't stay with the "player" #3 The camera leans when I push the Q or E Not sure how to best attach a sandbox file yet, but all Test_Forest has is a flat terrain and a tree in the middle. #include "engine.h" int main(int argc, char** argv) { Initialize(); RegisterAbstractPath("C:/Program Files/Leadwerks Engine SDK"); Graphics(1280,1024); AFilter() ; TFilter() ; TFramework framework=CreateFramework(); TLayer layer = GetFrameworkLayer(0); TCamera cam=GetLayerCamera(layer); PositionEntity(cam,Vec3(0,0,0)); //Set Lua variable BP L=GetLuaState(); lua_pushobject(L,framework); lua_setglobal(L,"fw"); lua_pop(L,1); // Setup Initial Post Processing FX SetGodRays(1); SetHDR(1); SetSSAO(1); SetBloom(1); SetAntialias(1); SetStats(2); Collisions(1,1,1); DebugPhysics(true); LoadScene("abstract::Test_Forest.sbx"); TBody player=CreateBodySphere(); EntityType(player,1); PositionEntity(player,Vec3(0,20,0)); SetBodyGravityMode(player,1); SetBodyMass(player,1); SetBodyDamping(player,1); SetWorldGravity(Vec3(0,-20,0)); TMesh ball=CreateSphere(); PositionEntity(ball,Vec3(0,20,0)); EntityParent(ball,player); EntityType(ball,1); TVec3 camrotation=Vec3(0); float mx=0; float my=0; float move=0; float strafe=0; float rotate=0; TEntity pivot=CreatePivot(player); EntityParent(pivot,player); EntityParent(cam,pivot); // MAIN LOOP while (!KeyHit(KEY_ESCAPE)) { //Player movement move=KeyDown(KEY_W)-KeyDown(KEY_S); strafe=KeyDown(KEY_Q)-KeyDown(KEY_E); rotate=KeyDown(KEY_D)-KeyDown(KEY_A); //Rotate Cam camrotation.Y=camrotation.Y+rotate; RotateEntity(pivot,camrotation,1); //Add Force to move player/ball TVec3 force=Vec3(strafe*10.0,0,move*10.0); force=TFormVector(force,cam,0); SetBodyForce(player,force); // Update timing and world UpdateFramework(); //Position the camera TVec3 playerpos=EntityPosition(player); TVec3 camerapos=EntityPosition(cam); camerapos.Y=Curve(playerpos.Y+1.75,camerapos.Y,2.0); camerapos=Vec3(playerpos.X,camerapos.Y,playerpos.Z-5); PositionEntity(cam,camerapos); // Render RenderFramework(); // Send to screen Flip(0) ; } return Terminate(); } Quote AMD Athlon 64 X2 4800+ 2GB RAM Nvidia GeForce 8800 GT (197.45 Driver) Windows Vista 32bit Link to comment Share on other sites More sharing options...
AggrorJorn Posted May 5, 2010 Share Posted May 5, 2010 For a start you could place this part //Position the camera TVec3 playerpos=EntityPosition(player); TVec3 camerapos=EntityPosition(cam); camerapos.Y=Curve(playerpos.Y+1.75,camerapos.Y,2.0); camerapos=Vec3(playerpos.X,camerapos.Y,playerpos.Z-5); PositionEntity(cam,camerapos); right after the main loop is created. At the moment your camera is being updated after the Update command. If you follow the Introduction to controllers tutorial (C++), you will see that you can replace the ball with the Controller. The pivot can remain the same although is not perse needed. 1 Quote Link to comment Share on other sites More sharing options...
Fosef Posted May 6, 2010 Author Share Posted May 6, 2010 For whatever reason, the controller code does not work for me...I copy it straight out of the .pdf. It runs fine, but the controller does not move. Quote AMD Athlon 64 X2 4800+ 2GB RAM Nvidia GeForce 8800 GT (197.45 Driver) Windows Vista 32bit Link to comment Share on other sites More sharing options...
Fosef Posted May 6, 2010 Author Share Posted May 6, 2010 Ok I got it moving, but still having issues with getting the camera to follow the controller and rotate correctly, here is what I have now.... #include "engine.h" int main(int argc, char** argv) { Initialize(); RegisterAbstractPath("C:/Program Files/Leadwerks Engine SDK"); Graphics(1280,1024); AFilter() ; TFilter() ; TFramework framework=CreateFramework(); TLayer layer = GetFrameworkLayer(0); TCamera cam=GetLayerCamera(layer); PositionEntity(cam,Vec3(0,0,0)); //Set Lua variable BP L=GetLuaState(); lua_pushobject(L,framework); lua_setglobal(L,"fw"); lua_pop(L,1); // Setup Initial Post Processing FX SetGodRays(1); SetHDR(1); SetSSAO(1); SetBloom(1); SetAntialias(1); SetStats(2); Collisions(1,1,1); DebugPhysics(true); LoadScene("abstract::Test_Forest.sbx"); TController player=CreateController(); EntityType(player,1); PositionEntity(player,Vec3(0,20,0)); SetBodyGravityMode(player,1); SetBodyMass(player,1); SetBodyDamping(player,1); SetWorldGravity(Vec3(0,-20,0)); TVec3 camrotation=Vec3(0); float mx=0; float my=0; float move=0; float strafe=0; float rotate=0; // MAIN LOOP while (!KeyHit(KEY_ESCAPE)) { //Player movement move=KeyDown(KEY_W)-KeyDown(KEY_S); strafe=KeyDown(KEY_Q)-KeyDown(KEY_E); rotate=KeyDown(KEY_D)-KeyDown(KEY_A); //Rotate Cam camrotation.Y=camrotation.Y+rotate; RotateEntity(player,camrotation,1); //Set controller input UpdateController(player,camrotation.Y+rotate,move*7,strafe*7,0,1,1,0); //Position the camera TVec3 playerpos=EntityPosition(player); TVec3 camerapos=EntityPosition(cam); camerapos.Y=playerpos.Y+1.75; camerapos=Vec3(playerpos.X,camerapos.Y,playerpos.Z-5); PositionEntity(cam,camerapos); // Update timing and world UpdateFramework(); // Render RenderFramework(); // Send to screen Flip(0) ; } return Terminate(); } Quote AMD Athlon 64 X2 4800+ 2GB RAM Nvidia GeForce 8800 GT (197.45 Driver) Windows Vista 32bit Link to comment Share on other sites More sharing options...
ZioRed Posted May 6, 2010 Share Posted May 6, 2010 With the following changes you will have a camera that stands behind the controller and rotate accordingly. 1. Create a Pivot for the cam and parent the cam to it: TPivot campiv = CreatePivot(); TCamera cam=GetLayerCamera(layer); EntityParent(cam, campiv); PositionEntity(cam,Vec3(0,0,0)); 2. Replace the code for positioning the cam with: //Position the camera TVec3 playerpos=EntityPosition(player); PositionEntity(campiv, playerpos); RotateEntity(campiv, EntityRotation(player)); MoveEntity(campiv, Vec3(0, 1.75, -5)); Don't know if that is what you needed. Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
DaDonik Posted May 6, 2010 Share Posted May 6, 2010 (edited) For me RotateEntity doesn't always do the job. For example when i did my spaceship movement code, i got problems with RotateEntity. When looking straight up Y+ or down Y-, the movement was not what i expected. Turn entity solved this problem for me. So instead of: //Rotate Cam camrotation.Y=camrotation.Y+rotate; RotateEntity(player,camrotation,1); you could write: //Rotate Cam TurnEntity(player, vec3(0.0F, rotate, 0.0F), 1); But that doesn't fix your problem, though. ZioRed's code looks like it's what your looking for, but you can do the same thing with a little less code. You can shrink: //Position the camera TVec3 playerpos=EntityPosition(player); PositionEntity(campiv, playerpos); RotateEntity(campiv, EntityRotation(player)); MoveEntity(campiv, Vec3(0, 1.75, -5)); down to: //Position the camera SetEntityMatrix(campiv, GetEntityMatrix(player)); MoveEntity(campiv, Vec3(0, 1.75, -5)); Hope this helps Edited May 6, 2010 by DaDonik Quote (Win7 64bit) && (i7 3770K @ 3,5ghz) && (16gb DDR3 @ 1600mhz) && (Geforce660TI) Link to comment Share on other sites More sharing options...
Fosef Posted May 6, 2010 Author Share Posted May 6, 2010 At work now, so will try it tonight Thanks guys! Quote AMD Athlon 64 X2 4800+ 2GB RAM Nvidia GeForce 8800 GT (197.45 Driver) Windows Vista 32bit Link to comment Share on other sites More sharing options...
Fosef Posted May 7, 2010 Author Share Posted May 7, 2010 Camera works as expected, but its very jerky when moving or strafing...rotation is fine. Also I can't figure out the Damping, I've tryed every number ranging from .1 to 100, it just keeps moving after releasing the keys. Quote AMD Athlon 64 X2 4800+ 2GB RAM Nvidia GeForce 8800 GT (197.45 Driver) Windows Vista 32bit Link to comment Share on other sites More sharing options...
macklebee Posted May 7, 2010 Share Posted May 7, 2010 Also I can't figure out the Damping, I've tryed every number ranging from .1 to 100, it just keeps moving after releasing the keys. increase the maxacceleration value to something like 300-500 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
AggrorJorn Posted May 7, 2010 Share Posted May 7, 2010 Whats the code you have now? Quote Link to comment Share on other sites More sharing options...
Fosef Posted May 7, 2010 Author Share Posted May 7, 2010 Ok, it stops fast when I release the keys now...But is still very jerky moving and strafing #include "engine.h" int main(int argc, char** argv) { Initialize(); RegisterAbstractPath("C:/Program Files/Leadwerks Engine SDK"); Graphics(1280,1024); AFilter() ; TFilter() ; TFramework framework=CreateFramework(); TLayer layer = GetFrameworkLayer(0); TCamera cam=GetLayerCamera(layer); PositionEntity(cam,Vec3(0,0,0)); //Set Lua variable BP L=GetLuaState(); lua_pushobject(L,framework); lua_setglobal(L,"fw"); lua_pop(L,1); // Setup Initial Post Processing FX SetGodRays(1); SetHDR(1); SetSSAO(1); SetBloom(1); SetAntialias(1); SetStats(2); Collisions(1,1,1); //DebugPhysics(true); LoadScene("abstract::Test_Forest.sbx"); TController player=CreateController(); EntityType(player,1); PositionEntity(player,Vec3(0,20,0)); SetBodyGravityMode(player,1); SetBodyMass(player,1); SetBodyDamping(player, 100); SetWorldGravity(Vec3(0,-20,0)); TVec3 camrotation=Vec3(0); float mx=0; float my=0; float move=0; float strafe=0; float rotate=0; TPivot campiv = CreatePivot(); EntityParent(cam, campiv); PositionEntity(cam,Vec3(0,0,0)); // MAIN LOOP while (!KeyHit(KEY_ESCAPE)) { //Player movement move=KeyDown(KEY_W)-KeyDown(KEY_S); strafe=KeyDown(KEY_Q)-KeyDown(KEY_E); rotate=KeyDown(KEY_D)-KeyDown(KEY_A); //Rotate Cam camrotation.Y=camrotation.Y+rotate; RotateEntity(player,camrotation,1); //Set controller input UpdateController(player,camrotation.Y+rotate*-1,move*10,strafe*10,0,400,1,0); //Position the camera TVec3 playerpos=EntityPosition(player); PositionEntity(campiv, playerpos); RotateEntity(campiv, EntityRotation(player)); MoveEntity(campiv, Vec3(0, 1.75, -5)); // Update timing and world UpdateFramework(); // Render RenderFramework(); // Send to screen Flip(0) ; } return Terminate(); } Quote AMD Athlon 64 X2 4800+ 2GB RAM Nvidia GeForce 8800 GT (197.45 Driver) Windows Vista 32bit Link to comment Share on other sites More sharing options...
macklebee Posted May 7, 2010 Share Posted May 7, 2010 try using the Curve function to get rid of the jerkiness: mx=Curve(MouseX()-GraphicsWidth()/2,mx,6); my=Curve(MouseY()-GraphicsHeight()/2,my,6); MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2); camrotation.X=camrotation.X+my/10.0; camrotation.Y=camrotation.Y-mx/10.0; RotateEntity(fw.GetMain().GetCamera(),camrotation,1); Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Fosef Posted May 8, 2010 Author Share Posted May 8, 2010 The rotation is fine, I can spin around 1080 without noticing any kind of jerking... I tried the curve...but I wouldn't doubt I didn't use it correctly, just seems to change the speed....but can still see the jerkyness UpdateController(player,camrotation.Y+rotate*-1,Curve(move*10,0,6),strafe*10,0,400,1,0); Are you guys getting the same results? Quote AMD Athlon 64 X2 4800+ 2GB RAM Nvidia GeForce 8800 GT (197.45 Driver) Windows Vista 32bit Link to comment Share on other sites More sharing options...
macklebee Posted May 8, 2010 Share Posted May 8, 2010 try it without modifying the move and strafe variables... look at the wiki tut for Character Controllers and you will see that the code doesn't use any multiplier on the move or strafe Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Fosef Posted May 10, 2010 Author Share Posted May 10, 2010 try it without modifying the move and strafe variables... look at the wiki tut for Character Controllers and you will see that the code doesn't use any multiplier on the move or strafe Arggh, the jerkiness was caused by lua scripts not loading again. When I set the abstract path to the LE SDK directory I thought it would take care of the scripts too. But I actually needed to move the scripts folder into MyGame folder? Anywho, thanks...got to see what a lot of the settings/parameters do trying to figure this out too, so the aggravation payed off a little. Quote AMD Athlon 64 X2 4800+ 2GB RAM Nvidia GeForce 8800 GT (197.45 Driver) Windows Vista 32bit Link to comment Share on other sites More sharing options...
ZioRed Posted May 10, 2010 Share Posted May 10, 2010 Yes the "Scripts" folder (and may be the shaders.pak if you use it, not sure for this) should ever be in the game executable folder, even if you register the SDK folder as abstract path. Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.