Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411281 Posts in 69324 Topics- by 58380 Members - Latest Member: bob1029

March 28, 2024, 11:19:05 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)[SOLVED]Help with Rotation of a bucket based on mouse movement.
Pages: [1]
Print
Author Topic: [SOLVED]Help with Rotation of a bucket based on mouse movement.  (Read 736 times)
Trash_Empire
Level 0
***



View Profile
« on: December 10, 2014, 05:49:28 PM »

I am working on a game, and it involves a bucket that has realistic physics depending on how you move the mouse. I want the bucket to rotate to the right if I accelerate the mouse to the right. I am using FlashPunk for my engine. I know how to set the angle and everything, I just would like to see a code snippet of receiving an acceleration variable every frame, and then I could probably handle applying the frame by frame acceleration to the angle of the image. This is pretty general, so I hope that someone more experienced than I could figure out how to do that. It sounds pretty simple, yet I just don't know where to start.

TL;DR how do you keep frame by frame acceleration of the mouse in a variable to perform conditional statements on to apply to rotation assuming I already have means of receiving Mouse coordinates? Any help would be greatly appreciated. Smiley Smiley Smiley
« Last Edit: December 12, 2014, 12:00:33 PM by DevLizard » Logged
oahda
Level 10
*****



View Profile
« Reply #1 on: December 10, 2014, 10:09:10 PM »

I seemed to recall that this is built in, and it seems to be right. Try it out: http://gamedev.stackexchange.com/questions/63348/box2d-making-a-body-follow-the-mouse-accurately
Logged

Trash_Empire
Level 0
***



View Profile
« Reply #2 on: December 11, 2014, 04:27:13 AM »

This is helpful, however I am interested in knowing how to have frame by frame acceleration variables so I can do it with other stuff in the future.
Logged
oahda
Level 10
*****



View Profile
« Reply #3 on: December 11, 2014, 05:14:33 AM »

Maybe you can find some helpful stuff in the source code related to that joint type.
Logged

nox
Level 0
***



View Profile WWW
« Reply #4 on: December 11, 2014, 05:30:04 AM »

You can find the acceleration of the mouse as follows:

Let mouse_1 be the current position of the mouse and mouse_2 be the position of the mouse from the prior frame. Further, v is velocity, a is acceleration, and dt is the time between frames/readings. Then,

v = (mouse_1 - mouse_2) / dt

a = (v_1 - v_2) / dt

Really, you probably want to keep a running average of accelerations over the past n frames, or something like that, to smooth out the values.
Logged

Trash_Empire
Level 0
***



View Profile
« Reply #5 on: December 11, 2014, 08:53:31 AM »

Thank you so much. I'll try this in my code later today. I'll update with further errors that are very likely later. Thanks again.
Logged
Trash_Empire
Level 0
***



View Profile
« Reply #6 on: December 11, 2014, 12:53:18 PM »

I just worked on the code, and I got something resembling what I want. It isn't very smooth, and it needs a lot of work before I can even apply this to the game logic, but it is a start. Thanks everyone. This has been very helpful.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic