gamecreator Posted February 28, 2010 Share Posted February 28, 2010 I'm experimenting with a ball game and I have a few problems I'm really hoping there are solutions to. First, whenever the ball falls off the edge, I put it back to its starting point but it doesn't quite work. It's always a bit above or below or to the side of where it should land. Is my position code wrong? Second, the camera follow code doesn't work. While it generally does follow the ball, it wobbles up and down and side to side as the ball moves. The slower the ball moves, the slower the camera wobbles. EDIT: Is it possible that the camera is positioned not on the pivot point of the ball (which is at the center) but rather the bottom of it (which is at 0,0)? I should test this. That would certainly explain the wobble. EDIT2: Tested. No change. Finally, I can't swear on it now because I can't reproduce it, but I think the physics may have changed depending on the program run. I don't yet alter any friction or anything but sometimes the ball made it up some ramps, even if barely, sometimes it only makes it half way. Sometimes it can stay half way up the ramp if I hold the button down, other times it starts rolling back anyway. Anyone ever have this issue and know what causes it? Here's the simple code I'm currently working with (I removed the initialization & loading code for this post): int main() { // ... while(!KeyHit(KEY_ESCAPE)) { if(KeyDown(KEY_LEFT)) AddBodyForce(ball,Vec3(-2,0,0)); if(KeyDown(KEY_RIGHT)) AddBodyForce(ball,Vec3(2,0,0)); if(KeyDown(KEY_UP)) AddBodyForce(ball,Vec3(0,0,2)); if(KeyDown(KEY_DOWN)) AddBodyForce(ball,Vec3(0,0,-2)); // If the ball fell far enough, restart it from checkpoint pos=EntityPosition(ball,1); if(pos.Y<-5) { PositionEntity(ball,Vec3(0.0,1.0,0.0)); SetBodyVelocity(ball,Vec3(0.0,0.0,0.0),1); SetBodyOmega(ball,Vec3(0.0,0.0,0.0),1); } // Follow ball with camera PositionEntity(camera,Vec3(pos.X,pos.Y+6,pos.Z-5)); UpdateFramework(); RenderFramework(); DrawText(400,400,"X = %f, Y = %f, Z = %f",pos.X,pos.Y,pos.Z); Flip(0); } exitapp: return Terminate(); } Any help would be much appreciated! Quote Link to comment Share on other sites More sharing options...
AndyGFX Posted February 28, 2010 Share Posted February 28, 2010 I think that this link, help you. Third person camera - ball game example Quote [HW] C2D Q6600, 4GB RAM, NV8800GTX, Vista Ultimate x64 [sW] Blide Plus, BlitzMax, Delphi, C++, 3DWS 5.53, Leadwerks 2.xx Link to comment Share on other sites More sharing options...
gamecreator Posted February 28, 2010 Author Share Posted February 28, 2010 Thanks for that but I've already seen it (and will switch to his method if no one can figure out why this one's wrong). His code is more complex and I guess I'm wondering why. Why is the simple way wrong (or is it)? Quote Link to comment Share on other sites More sharing options...
Marleys Ghost Posted February 28, 2010 Share Posted February 28, 2010 how are you creating the ball? Quote AMD Bulldozer FX-4 Quad Core 4100 Black Edition 2 x 4GB DDR3 1333Mhz Memory Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5 Windows 7 Home 64 bit BlitzMax 1.50 • Lua 5.1 • MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro 3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET LE 2.5/3.4 • Skyline • UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0 Marleys Ghost's YouTube Channel • Marleys Ghost's Blog "I used to be alive like you .... then I took an arrow to the head" Link to comment Share on other sites More sharing options...
gamecreator Posted February 28, 2010 Author Share Posted February 28, 2010 Loaded via TModel ball=LoadModel("abstract::ball.gmf"); Quote Link to comment Share on other sites More sharing options...
Marleys Ghost Posted February 28, 2010 Share Posted February 28, 2010 is the origin of the model centred? Quote AMD Bulldozer FX-4 Quad Core 4100 Black Edition 2 x 4GB DDR3 1333Mhz Memory Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5 Windows 7 Home 64 bit BlitzMax 1.50 • Lua 5.1 • MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro 3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET LE 2.5/3.4 • Skyline • UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0 Marleys Ghost's YouTube Channel • Marleys Ghost's Blog "I used to be alive like you .... then I took an arrow to the head" Link to comment Share on other sites More sharing options...
gamecreator Posted March 1, 2010 Author Share Posted March 1, 2010 If you mean the pivot point then yes, in both Max and the Model Viewer, it's centered in the middle of the ball. I just tested replacing the sphere's .phy file with a box .phy file and the camera bouncing goes away, until the ball falls off the edge. Then it wobbles again. Also, unfortunately, after I replaced the ball's .phy file with the correct one, I was able to go up a ramp I was never able to go up before. Quote Link to comment Share on other sites More sharing options...
gamecreator Posted March 1, 2010 Author Share Posted March 1, 2010 Ok. I just solved two of my three problems. For some reason, Leadwerks uses the global position from Max as the pivot point, not the pivot point itself (even though the exporter exports it correctly, as seen in the Model Viewer). This explains the camera wobble. This also explains the misplacing of the ball at 0,0. When the ball was told to go to 0,0, it placed the ball based on where its bottom was. If the bottom was tilted out because the ball moved/rotated a little, it offset the ball and so it was offset that much from 0,0. Follow? Now I hope maybe my physics quirk is fixed too. Thanks everyone for the help!! I guess a related follow-up question: is the timing on the physics correct in the code? I mean, will the ball move at the same speed for everyone? Quote Link to comment Share on other sites More sharing options...
gamecreator Posted March 1, 2010 Author Share Posted March 1, 2010 Ok. Physics is definitely wrong. I put in a second directional light (which I guess is wrong because it glitched the graphics up) and now the ball won't even go up the first small ramp. What am I doing wrong?? (Sorry about the triple post.) Quote Link to comment Share on other sites More sharing options...
Rick Posted March 1, 2010 Share Posted March 1, 2010 You should only put in 1 directional light because having more causes known bugs. Quote Link to comment Share on other sites More sharing options...
gamecreator Posted March 1, 2010 Author Share Posted March 1, 2010 But it causes such cool effects! ;P Really, yeah, I got that figured. And I'm guessing the final problem is simply because I need to put timing in. Will test to make sure. Thanks again for everyone's help! Quote Link to comment Share on other sites More sharing options...
VeTaL Posted March 2, 2010 Share Posted March 2, 2010 I want to continue this thread about camera. I'm programing on Lite-c about 6 years, so usually i place 3rd person camera with converting sphere coordinates to XYZ coordinates, something like // moving camera around center camera.x = center.x - camera_distance * cos(entity.pan) * cos(camera.tilt); camera.y = center.y - camera_distance * sin(entity.pan) * cos(camera.tilt); camera.z = center.z - camera_distance * sin(camera.tilt); Now i'm interested in "parent" variant. // 1) So, now i place camera camera = GetLayerCamera(layer); // 2) Then i move it on the offset to pivot PositionEntity(cam,Vec3(0,4,-2)); // 3) And last one i set pivot to camera's parent, so it would follow pivot with offset. if (!pivot) {FreeEntity(pivot); } pivot = CreatePivot(target); EntityParent(camera, pivot); Now the question: how can i control offset? For example, i want change distance to pivot as player rolls mouse wheel... Do i may to re-position camera as on 2nd step and then assign it to the pivot like in 3rd step? Quote Working on LeaFAQ Link to comment Share on other sites More sharing options...
Canardia Posted March 2, 2010 Share Posted March 2, 2010 PositionEntity( camera, EntityPosition(camerapivot) ); RotateEntity( camera, EntityRotation(camerapivot) ); MoveEntity( camera, Vec3(0,0,cameraZoffset) ); To move 3rd person camera closer and further, just change the value of cameraZoffset. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
VeTaL Posted March 2, 2010 Share Posted March 2, 2010 Excellent solution, but i'm interested if its possible to work with "parent" method. Quote Working on LeaFAQ Link to comment Share on other sites More sharing options...
Marleys Ghost Posted March 2, 2010 Share Posted March 2, 2010 There were some issues when parenting fw.Main.camera to a pivot. Quote AMD Bulldozer FX-4 Quad Core 4100 Black Edition 2 x 4GB DDR3 1333Mhz Memory Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5 Windows 7 Home 64 bit BlitzMax 1.50 • Lua 5.1 • MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro 3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET LE 2.5/3.4 • Skyline • UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0 Marleys Ghost's YouTube Channel • Marleys Ghost's Blog "I used to be alive like you .... then I took an arrow to the head" Link to comment Share on other sites More sharing options...
VeTaL Posted March 2, 2010 Share Posted March 2, 2010 Wow, very useful link. Quote Working on LeaFAQ Link to comment Share on other sites More sharing options...
VeTaL Posted March 2, 2010 Share Posted March 2, 2010 And... what about collision detection for camera? What is faster: - to send 4 rays from every corner of the camera to player, if something intersect ray, then move camera closer - create pseudo-physic body(capsule, maybe) without mass, and place it between camera and player? Quote Working on LeaFAQ Link to comment Share on other sites More sharing options...
Canardia Posted March 2, 2010 Share Posted March 2, 2010 Physics body can get stuck in the environment (unless you have some pathfinding for it), so I guess 4 entitypicks is better. I would however move the camera closer only when all picks can't see the player, and not when only 1 can not see. The EntityVisible command also checks for the center pivot of the model only, which is kinda useless. It would be more useful if there was a parameter to say: 0=center visible, 1=completely visible, 2=partially visible. Then you could use option 2 for 3rd person camera checks. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
VeTaL Posted March 2, 2010 Share Posted March 2, 2010 //Physics body can get stuck No-no... without physic, just for collision detection. //I would however move the camera closer only when all picks can't see the player, and not when only 1 can not see. Why? Then, its better to send only 1 pick, from the camera point. Quote Working on LeaFAQ Link to comment Share on other sites More sharing options...
Canardia Posted March 2, 2010 Share Posted March 2, 2010 Why? Then, its better to send only 1 pick, from the camera point.It's quite annoying when the camera moves just because a little toe is hiding behind a little stone on the ground (one ray can not see 1 corner). I'm much happier when the camera doesn't move closer when I still can see 1cm of the top of my head, because then I know the rest of the body is also there, no need to show it. Only when I can't see anything of the player body, then I lose orientation and need to move the camera closer until I can see at least something of the player. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Rick Posted March 2, 2010 Share Posted March 2, 2010 1 ray cast works just fine. You can determine what entity types would effect the raycast so you could make some things not be affected by this raycast. The EntityVisible command also checks for the center pivot of the model only, which is kinda useless. This is why you don't parent the camera to the player, but instead create a pivot that follows the player. You offset the pivot from the player to determine where you want the camera pointing (the head most likely). Then you do entity visible between the player pivot and the camera or camera pivot. The other reason to do this is that most 3rd person games allow you to rotate the camera freely from the player rotating. By having a player pivot that follows the player, you can just rotate that and the camera will follow since it's parented to that player pivot. This will rotate the camera independently from the player very easily. Note that when you do the entity visible between the 2 pivots you'll have to worry about the actual player model. I generally just hide the player model, do the entity visible check, then unhide the player model. Quote Link to comment Share on other sites More sharing options...
VeTaL Posted March 2, 2010 Share Posted March 2, 2010 Okay... I was thinking about capsule body for collision.. But you're right, i may not move camera closer because of some small items, that can intersect line. Quote Working on LeaFAQ Link to comment Share on other sites More sharing options...
VeTaL Posted March 2, 2010 Share Posted March 2, 2010 //The other reason to do this is that most 3rd person games allow you to rotate the camera freely from the player rotating. By having a player pivot that follows the player, you can just rotate that and the camera will follow since it's parented to that player pivot. This will rotate the camera independently from the player very easily. Of course, i just wanted to handle camera to something like player Quote Working on LeaFAQ 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.