Jump to content

Apply force via camera view


AggrorJorn
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

  • Upvote 1

Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10.

Link to comment
Share on other sites

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) 

Link to comment
Share on other sites

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.

post-702-12722884801115_thumb.png

Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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..

Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...