Need to put a limit on a loop

3 ビュー (過去 30 日間)
brian grove
brian grove 2015 年 5 月 20 日
回答済み: Walter Roberson 2015 年 5 月 20 日
I have an elseif statement that detects when a ball enters into a circle. The problem is that once the ball enters the circle it does not leave fast enough sometimes and keeps running the else if statement. I need the loop to only execute once and then wait a certain amount of time before it can be used again.
elseif distsq1 <= Circle1Radius.^2
plot(circleXs,circleYs,'b');
bounce([(ballVector(1)), (Y_FACTOR + -1*(ballVector(2)))]);
Thoughts?

採用された回答

Walter Roberson
Walter Roberson 2015 年 5 月 20 日
Set a variable to be true when you detect you are inside the circle and false when you detect you are outside. Then in the else condition, you still need to test whether you are still inside the circle, but if you find you are and the flag is already set, don't do anything.
You can adjust this to be a counter instead of true/false, if you want to ignore it for a certain number of times. You can adjust it to be a flag and also a record of the time you bounce()'d it, if you want to check by time.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by