AggrorJorn Posted April 25, 2010 Share Posted April 25, 2010 I've been struggling with forces for the past 2 weeks. I am getting weird results, the direction seems to change during rolling of the ball. move = KeyDown(KEY_W)-KeyDown(KEY_S) strafe = KeyDown(KEY_A)-KeyDown(KEY_D) force = Vec3(strafe*10,0,move*10) force = TFormVector(force,fw.main.camera,nil) ballBody:AddForce(force) Does anybody see something wrong with this piece of code. Quote Link to comment Share on other sites More sharing options...
Joh Posted April 26, 2010 Share Posted April 26, 2010 Could you show the "defeinition" of ballbody? You need to set the damping correctly. Quote Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10. Link to comment Share on other sites More sharing options...
AggrorJorn Posted April 26, 2010 Author Share Posted April 26, 2010 The first topic has the entire lua code. you can run it directly from the Lua script editor. Never used damping before. I'll take a look into it. thanks for your answer. Quote Link to comment Share on other sites More sharing options...
Joh Posted April 26, 2010 Share Posted April 26, 2010 So this is the whole code? Seem strange.. Do you place the cam on the ball then? Do you rotate the cam in some way? Quote Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10. Link to comment Share on other sites More sharing options...
AggrorJorn Posted April 26, 2010 Author Share Posted April 26, 2010 The third person camera is a direct conversion from the code I once created with C++: http://leadwerks.com/werkspace/index.php?/files/file/121-third-person-camera-ball-game-example/ I create a pivot at the balls position and let the camera rotate around this pivot. I don't really understand the entire way but it has always worked well. Do you think that the camera is interfering with the forces? Quote Link to comment Share on other sites More sharing options...
Joh Posted April 26, 2010 Share Posted April 26, 2010 Of course it do! force = TFormVector(force,fw.main.camera,nil) In this part of code you are telling : Find the position of force (strafe and move so lateral and frontal) starting as camera current position and rotation (local space of camera). Tform TransFORM the space from global to local and so on. So using the camera as referred point it will find that point BASED on camera. You should use another entities if you don't want have weird movement. 1 Quote Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10. Link to comment Share on other sites More sharing options...
AggrorJorn Posted April 26, 2010 Author Share Posted April 26, 2010 Thanks for your answer Joh. My mind theoraticly understands what your saying, but sometimes it just doesn't seem to 'get' the logical part. I changed the following and it works now. It is a really minor edit. It is always funny to see how one small thing can waste an entire weekend searching for a problem. ballBody:AddForce(force) to ballBody:AddForce(force,1) Quote Link to comment Share on other sites More sharing options...
Joh Posted April 26, 2010 Share Posted April 26, 2010 My mind theoraticly understands what your saying, but sometimes it just doesn't seem to 'get' the logical part. I don't like this answer So look this image The black lines are global space (the 3d coord.) the black square is your cam, and the red line are the local space of your cam. What are you doing is asking to calculate the force based on the cam pos and rot (wich is wrong if you wanna have a free cam) so probaly it will be better to create a pivot and place it in the same position of the ball and use that pivot to calculate the force, also if you wanna rotate the ball you should instead rotate the pivot. ballBody:AddForce(force,1) ARE YOU SURE THIS WORK??? It's really strange if it is.. Look here: AddBodyForce( body:TBody, force:TVec3 [, global:Int=1 ] ) [, global:Int=1 ] This mean that as for default is 1. Quote Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10. Link to comment Share on other sites More sharing options...
AggrorJorn Posted April 26, 2010 Author Share Posted April 26, 2010 I understand what you mean Joh and thanks for the drawing. It is weird that the force works correctly since it is the default. But try the attached script in the lua script editor (not the one inside the Leadwerks editor). Although it works fine now, if you look closely you will see that sometimes the camera tilts a little bit. try removing the ',1' at line 93. You will see that it wont work. Quote Link to comment Share on other sites More sharing options...
Joh Posted April 26, 2010 Share Posted April 26, 2010 Can't try it now (i am working) but i'll do when i'll be in my home. Anyway i looked at it, and don't know why is working. ballControlPivot = CreatePivot() move = KeyDown(KEY_W)-KeyDown(KEY_S) strafe = KeyDown(KEY_D)-KeyDown(KEY_A) force = Vec3(strafe*Speed,0,move*Speed) force = TFormVector(force,ballControlPivot,nil) ballBody:AddForce(force,1) ballControlPivot.SetPosition(ballBody.GetPosition()) This should work probably better.. Also in this case you could rotate your ball in any rotation without worryng about camera. EDITED: Noticed that ballPivot was already used.. Quote Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10. 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.