Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Ball Movement

Author
Message
timthepig
21
Years of Service
User Offline
Joined: 27th Feb 2005
Location:
Posted: 27th Feb 2005 22:33
I want to able to kick a football, basically emulate those free kick games(you push space then the ball travels towards the goal). However I cannot get a smooth animation and ball movement. -I've used :-

If spacekey()=1
For kick=0 to #max
wait (1)
move object 10, #ballkick
next kick
EndIf

However this just doesn't give a flowing movement, it seems to travel oddly. I know I'm missing something basic in the movement of the object which could solve all my troubles. Any feedback would be great.

I don't using wait statements as a efficient way of getting a continual movement on an object - I know someone will be able to give me a decent answer

Cheers!
NanoBrain
21
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 1st Mar 2005 13:42 Edited at: 1st Mar 2005 13:46
Timthepig,

First of all, I would prefer not using a FOR NEXT loop to create the ball movment. The reason why you get such odd movement, is because the fact that the FOR NEXT loop is completely looped in one program loop. Let me specify by saying, that if your FOR NEXT loop is to loop 5 times, then it would have looped 25 times total, after just 5 program loops.

Instead of using a FOR NEXT loop to execute this scenario, create a piece of code, function or not, within your program that is executed every time your program loops. [EX]


This is your basic setup for making objects move fluently within this type of language. FOR NEXT loops are fully executed within 1 main program loop. They are usually only used to retrieve data within a moment or anything else that needs to be calculated within one program loop. [EX]I have used a FOR NEXT loop to draw a circle of dots, every loop, which represent a player's boundaries. Instead of using them, use state variables to only execute something if that state is turned to "on". This way, in each program loop, the specific code will be executed. Using a FOR NEXT loop, like you did, probably made your ball to translate quickly from the starting position to the ending position. This is because it was completely executed within one screen refresh.

+NanoBrain+
Los
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Location:
Posted: 1st Mar 2005 14:37
Nice for loop stuff Brain. I was just thinking instead of keeping to just the one main loop could you branch off and start another do loop within the main one? When it detects the space key, ignore everything else and concentrate on moving the ball towards the goal and when it reaches the goal Y or X position exit the loop? I know this would mean you don't get the crowd wiggling if he wanted one.. but that could be in a gosub within the ball kicking code.



Never been experienced at this lot yet but I've heard about using lots of do-loops to split the program up. Maybe that was just for checking an input in text/business programs?

" Ahh to finish something! My boy, have you ever accomplished anything? "
timthepig
21
Years of Service
User Offline
Joined: 27th Feb 2005
Location:
Posted: 2nd Mar 2005 03:13
I understand what your saying - thanks a lot however - my question is how to get a smooth ball motion? (move object, doesn't give a smooth motion - eg, the ball seems to move too fast and frame rate drops etc)
NanoBrain
21
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 3rd Mar 2005 15:35 Edited at: 3rd Mar 2005 15:56
Timthepig,

Again, I say that the FOR NEXT loop is creating a non smooth motion, due to the screen not being refreshed after each loop within it. The way you have your program set up above, the ball motion will be very fast and very jerky, and could possibly be what is making the program to run slow. Also, you have included a WAIT command in the midst of the FOR NEXT loop for a reason that I do not understand. This will make your program to seem as if it is running slow, because it literally keeps ANY code from being processed for the time specified.

Let's say that the FOR NEXT is to loop five times upon each execution of it. Let's also say that your ball is supposed to move 1.50 units each loop. The total movement of the ball, at the ending of the FOR NEXT loop, would be 7.50 units.

Since you are not using the SYNC command within the FOR NEXT loop to update your screen each loop, you will see the ball to move 7.50 units each program loop. Let me clarify, by saying that at screen refresh A, your ball could be at 0 units. At screen refresh B, your ball will be 7.50 units away from where it originally was at the last screen refresh.

In the code below, let's say that #max(which should be max# because it is not processed as a real number variable until the pound sign is placed after it;same goes for #ballkick) = 5 and #ballkick = 1.50.

Do
If spacekey()=1
For kick=0 to #max
wait (1),
move object 10, #ballkick
next kick
EndIf
Sync
Loop

Let's say that object 10 is at 0 units, initially. When the screen is refreshed, which in this code it is not within the FOR NEXT loop, object 10 will be 7.50 units away from where it was. At one moment you will see the object at 0 units, and the next moment it will be 7.50 units away from 0. This is where your jerky movement is coming from. That every time you press the spacekey, your ball is translated 7.50 units away from where it was before you pressed the spacekey. In this, you are not seeing it move 1.50 by 1.50 units each time the screen refreshes.

If you wish to keep the FOR NEXT loop, then simply place the SYNC command inside the FOR NEXT loop at the end of the code it loops.

Do
If spacekey()=1
For kick=0 to #max
wait (1),
move object 10, #ballkick
sync
next kick
EndIf
Sync
Loop

I believe I answered your question correctly. However, you did not understand what I explained.

+NanoBrain+
timthepig
21
Years of Service
User Offline
Joined: 27th Feb 2005
Location:
Posted: 4th Mar 2005 03:20
Yes you are right - I'm sorry!!

I thank you - because it did struck a chord what you said. My previous programming experience doesn't involve real-time programming which I need to understand these obstacles - I'm getting a better understanding already. I've got the ball moving nicely. Now I'm attaching a limb to a hidden sphere - where an arrow moves around the ball. Now I have the task of detecting the angle of the arrow when the space is pushed - using get angle ?() - but the angle of the arrow is somewhat screwed - its the way I've positioned it. I'll work it out somehow...hehehe

I appreciate your post.

Thanks again
Baggers
22
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 4th Mar 2005 05:54
I think Nano is right, the other reason your ball wont move realisticaly is that the ball never moves at a constant rate in football, there is always acceleration and deceleration. Also gravity is important in these situations.
Now i know these sort of things can be achieved in DB, although i didnt do them when i used it, im a DBpro guy now and thus i use vectors alot as it makes storing speeds and modifying them much easier, i was wondering does DBC-expansion have a Vector system ?

For basic gravity code, have a look in the DBPro board ive been in 3 gravity questions this week so they are easy to find.

Good Luck Tim

Login to post a reply

Server time is: 2026-07-11 14:17:45
Your offset time is: 2026-07-11 14:17:45