Jump to content
  • Advertisement
Sign in to follow this  
mamanybono

Changing ball direction according to GUI object.

This topic is 1499 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everybody. I searched google but could not find something enough siple for me. Could you 
 
please help me.
 
The case is this: There is a ball on scene and a kick button also there is a gui object 
 
which is for determining the ball direction.
 
There is 120 level on gui object. The level is changing by time but I want it to be fast, 
 
because user should not catch it easly. Cany we change the levels according to milisecond 
 
for example per 2 milisecond 1 level.
 
After this, how can get the value of gu? object's value when I press the kick button and 
 
give it to ball as a direction. Thanks a lot for your helps.
 
By the way, I am using javascript.

Share this post


Link to post
Share on other sites
Advertisement
I think you're approaching this backwards.

Assuming you want it framerate independent, maybe you can divide the difference in time between frames by an appropriate interval to provide a function to tell you your "direction" change, then represent this variable in the UI. You wouldn't read the UI to get the direction, but use the direction value to set the UI. When it's clicked, you just check the time it was clicked and compare it to the previous time and direction to derive the appropriate direction for that click time.

Say, you want it to travel one degree of your 120 each milisecond. You would check the time at the point of drawing your frame, compare it to the previous one (subtract), and then divide by a milisecond. Then add that to the previous direction value to get your new one.

If it's going back and forth, you may want to toggle a bool when you go over/under a certain degree, and add/subtract the difference to account for the "bounce" that happened between frames.

Share this post


Link to post
Share on other sites

I think you're approaching this backwards.

Assuming you want it framerate independent, maybe you can divide the difference in time between frames by an appropriate interval to provide a function to tell you your "direction" change, then represent this variable in the UI. You wouldn't read the UI to get the direction, but use the direction value to set the UI. When it's clicked, you just check the time it was clicked and compare it to the previous time and direction to derive the appropriate direction for that click time.

Say, you want it to travel one degree of your 120 each milisecond. You would check the time at the point of drawing your frame, compare it to the previous one (subtract), and then divide by a milisecond. Then add that to the previous direction value to get your new one.

If it's going back and forth, you may want to toggle a bool when you go over/under a certain degree, and add/subtract the difference to account for the "bounce" that happened between frames.

 

 

I could not use GUI object but, I found different way, I am moving ball to right side to left then left to right, for this I used 2 cubes near the ball, the cubes are applying force to ball :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!