gamecreator Posted August 12, 2011 Share Posted August 12, 2011 Hello. How do you avoid the bounce of a character controller on a ramp? The problem is twofold: 1. It looks bad to have a character bounce down a ramp when they should be running 2. ControllerAirborne is usually 1 which means that if you use that to detect if you can jump, you're out of luck. Most of the time the character can't. Below is a quick video and the code: #include "engine.h" #pragma warning(disable:58) int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd ) { if(!Initialize()) return 1; RegisterAbstractPath("D:/Programming/Leadwerks Engine SDK"); // Set graphics mode if(!Graphics(640,480)) { MessageBoxA( 0,"Failed to set graphics mode.","Error",0); return 1; } // Create framework object and set it to a global object so other scripts can access it TFramework fw = CreateFramework(); if(fw==NULL) { MessageBoxA(0,"Failed to initialize engine.","Error",0); return 1; } // Set Lua framework object SetGlobalObject("fw",fw); // Set Lua framework variable BP lua=GetLuaState(); lua_pushobject(lua,fw); lua_setglobal(lua,"fw"); lua_pop(lua,1); // Get framework main camera TCamera camera = GetLayerCamera(GetFrameworkLayer(0)); PositionEntity(camera,Vec3(13,5,-12)); RotateEntity(camera,Vec3(15,0,0)); TLight light=CreateDirectionalLight(); RotateEntity(light,Vec3(45,45,45)); SetWorldGravity(Vec3(0,-80,0)); TModel level=LoadModel("abstract::level.gmf"); if (!level) { MessageBoxA(0,"Error","Failed to load mesh.",0); goto exitapp; } EntityType(level,2); TController player=CreateController(1.8,0.4,0.5,45.01); EntityType(player,1); SetBodyMass(player,10); PositionEntity(player,Vec3(0,1,0)); float move=0.0; float strafe=0.0; TEntity backwall = CreateBodyBox(50,50,1,0); MoveEntity (backwall, Vec3(0,0,-1)); SetBodyMass (backwall, 0); EntityType (backwall, 2); TEntity frontwall = CreateBodyBox(50,50,1,0); MoveEntity (frontwall, Vec3(0,0,1)); SetBodyMass (frontwall, 0); EntityType (frontwall, 2); Collisions(1,2,true); Collisions(1,2,true); DebugPhysics(1); SetAntialias(1); while(!KeyHit(KEY_ESCAPE)) { TVec3 pos; TVec3 vel; move=KeyDown(KEY_RIGHT)-KeyDown(KEY_LEFT); pos=EntityPosition(player,1); PositionEntity(camera,Vec3(pos.X,pos.Y+4,-15)); PositionEntity(backwall, Vec3(pos.X,pos.Y,-1)); PositionEntity(frontwall, Vec3(pos.X,pos.Y,1)); move*=10; float jump=0.0; if (KeyHit(KEY_S)) { if (!ControllerAirborne(player)) { jump=30.0; } } UpdateController(player,270.0,move,0.0,jump,50); UpdateFramework(); RenderFramework(); DrawText(0,20,"move: %f",move); DrawText(0,40,"airborne: %d",ControllerAirborne(player)); Flip(0); } return Terminate(); } I really need to guarantee that the controller stays flat on the ground whenever it's moving downhill. Thanks for any help. Quote Link to comment Share on other sites More sharing options...
Canardia Posted August 12, 2011 Share Posted August 12, 2011 The bouncing comes from the fact, that the player is moving forward, and not downward. You could add a downforce to the player to make it move also downward. 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...
gamecreator Posted August 12, 2011 Author Share Posted August 12, 2011 True. Gravity doesn't pull it down fast enough. Now, since forces and positioning don't work on character controllers, what are my options? Some sort of hack with a negative jump? Imagine if the character was going even faster (something like Sonic the Hedgehog) but it still needed to stay on the ground. I'd love to get this to work as I really like that the sliding joints work with character controllers (for moving platforms and such) but I may have to code the physics and collision myself. Quote Link to comment Share on other sites More sharing options...
Canardia Posted August 12, 2011 Share Posted August 12, 2011 I think a simple MoveEntity(player,0,-0.1*AppSpeed(),0) would do. 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...
gamecreator Posted August 12, 2011 Author Share Posted August 12, 2011 Thanks and I'll try that but if PositionEntity doesn't work on controllers, I suspect MoveEntity won't either. Quote Link to comment Share on other sites More sharing options...
Canardia Posted August 12, 2011 Share Posted August 12, 2011 Sure it works, I use it all the time. 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...
gamecreator Posted August 12, 2011 Author Share Posted August 12, 2011 Do they both? Any idea what I did wrong here? Or just MoveEntity? I'll try the latter when I get home regardless. Would be awesome if it worked. Quote Link to comment Share on other sites More sharing options...
gamecreator Posted August 13, 2011 Author Share Posted August 13, 2011 Tried MoveEntity(player,Vec3(0,-0.1*AppSpeed(),0),0); after UpdateController. No luck. It took control away completely and the Controller just slowly floated down, through the ground. Thanks for the suggestion though. Quote Link to comment Share on other sites More sharing options...
Canardia Posted August 13, 2011 Share Posted August 13, 2011 I tried the FPS demo which I found somewhere, but it was based on this tutorial: http://www.leadwerks.com/werkspace/page/Documentation/LE2/tutorials/_/programming/cpp/character-controllers-r15 There you can walk down the ramps and it doesn't bounce at all, so you should check your parameters that you have similar values. 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...
gamecreator Posted August 13, 2011 Author Share Posted August 13, 2011 Their move value is 1 while walking, 2 while running. Mine is 10. I guess one solution could be to scale down the world and player to a 10th of their size and then use smaller values. But I suspect this issue will still come up with steeper ramps. I wish Leadwerks handled this. I appreciate the help Metatron. Quote Link to comment Share on other sites More sharing options...
Canardia Posted August 13, 2011 Share Posted August 13, 2011 I will work with steeper ramps too, because then the player slides automatically down, and you don't need to move forward at all. See the example I posted, there you have 3 different steep ramps to test all situations. 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...
gamecreator Posted August 13, 2011 Author Share Posted August 13, 2011 Yeah but apparently not with a move speed of 10. Quote Link to comment Share on other sites More sharing options...
Canardia Posted August 13, 2011 Share Posted August 13, 2011 You can't really use that big size, because it will mess up all physics behaviour too, and you can see directional light shadows only like up to 50 meter far away (500 meter with the default scale). The get the best functionality of the engine, you should use the default scale. Smaller works too, but not much smaller. 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...
gamecreator Posted August 13, 2011 Author Share Posted August 13, 2011 I guess I'm out of options then except to write my own physics/collision detection and to add a few extra steps to my pipeline. Quote Link to comment Share on other sites More sharing options...
Canardia Posted August 13, 2011 Share Posted August 13, 2011 Why can't you just use the default scale for your models? 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...
gamecreator Posted August 13, 2011 Author Share Posted August 13, 2011 Because at the default scale I need to move the character at a speed of 10 (like in the video) or it will seem too slow. And then it bumps on the hills. Quote Link to comment Share on other sites More sharing options...
Canardia Posted August 13, 2011 Share Posted August 13, 2011 You should just use the parameters like in the tutorial and everything will work fine. In your example you have set the gravity 40 times bigger, the mass of the player 10 times bigger, and other things, so it can never work normal that way. 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...
gamecreator Posted August 13, 2011 Author Share Posted August 13, 2011 As expected, setting everything to the tutorial values made the controller move incredibly slow. I had the move speed at 2 (the run speed in the tutorial). Setting it to 3 already made the controller bump off the ramp. (I even got rid of the side backwall and frontwall entities just in case there was friction there.) Quote Link to comment Share on other sites More sharing options...
Josh Posted August 22, 2011 Share Posted August 22, 2011 It's behaving correctly. -You are applying horizontal force to the player, even when they are airborne. You should greatly reduce their movement when airborne. -Your movement is quite strong compared to gravity. Turn the movement down or increase the gravity, or both. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
gamecreator Posted August 22, 2011 Author Share Posted August 22, 2011 Gravity is already -80 (it's -20 in the Leadwerks example). It falls fast enough when you just walk off a ledge so I'd rather not increase that. And if I decrease the speed the character moves slowly. I'll start from scratch but this is pretty baffling. Thanks for the suggestions though. Quote Link to comment Share on other sites More sharing options...
Josh Posted August 22, 2011 Share Posted August 22, 2011 It sounds like you want it travelling at the same velocity, perpindicular to the normal of the ground. Take the vertical velocity and use that to create a vector with the horizontal movement to calculate how much the horizontal movement should be reduced by, You should definitely multiply the movement by something like 0.1 when the controller is airborne. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
franck22000 Posted August 22, 2011 Share Posted August 22, 2011 Hello GameCreator, try this in your movement code loop: SetBodyVelocity(yourcontroller, Vec3( GetBodyVelocity(yourcontroller).X,- 10.0f, GetBodyVelocity(yourcontroller).Z) ); use it only if the controller is not airborne and it should fix your issue Quote You guys are going to be the death of me. Josh Link to comment Share on other sites More sharing options...
gamecreator Posted August 23, 2011 Author Share Posted August 23, 2011 Thank you for the suggestion. It actually did what I was looking for, though it introduced some new problems. I'll keep at it. Thank you for everyone's help! Quote Link to comment Share on other sites More sharing options...
franck22000 Posted August 23, 2011 Share Posted August 23, 2011 Wich is the problem that appears please ? It might be usefull for me to know Quote You guys are going to be the death of me. Josh Link to comment Share on other sites More sharing options...
gamecreator Posted August 23, 2011 Author Share Posted August 23, 2011 I plan on writing my own collision detection so there's no need to solve these problems on my account but 1. When the character goes down the ramp, it is often still considered airborne so you can't jump (even if it looks like he's on the ground). A lower velocity might solve this. 2. When jumping on the ramp, sometimes the character falls straight through it now. Quote 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.