Changing ball direction according to GUI object.

Started by
1 comment, last by mamanybono 9 years, 6 months ago
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.
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.

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 :)

This topic is closed to new replies.

Advertisement