フィルターのクリア

Need to make a ball bounce off a circle.

1 回表示 (過去 30 日間)
brian grove
brian grove 2015 年 5 月 19 日
コメント済み: Chad Greene 2015 年 5 月 20 日
I have a pong game that I want to add a function circular bumper to. I already have a way of detecting when the ball enters the circle but now I need to figure out how to make it bounce off the wall of the circle.
My function for bouncing the ball off the walls is
function bounce (tempV)
%normalize vector
tempV(1) = tempV(1) ./ (sqrt(tempV(1)^2 + tempV(2)^2));
tempV(2) = tempV(2) ./ (sqrt(tempV(1)^2 + tempV(2)^2));
ballVector = tempV;
and I feed the function something along these lines...
bounce([ballVector(1), -1 * (Y_FACTOR + abs(ballVector(2)))]);
but I can't get it to work for the circle... any ideas?
  1 件のコメント
Chad Greene
Chad Greene 2015 年 5 月 20 日
We don't have enough information about your variables. Whether you're giving a talk or writing a report or posting on a forum, always explicitly describe any variable you ever show. If a variable is not relevant, do not show it to us. If a variable is relevant, describe it.
To increase your chances of getting helpful responses, provide a picture of what you're trying to do and some simple working code that we can tinker with.
When I look at your code, all I see is not related to your question, but you can replace
sqrt(tempV(1)^2 + tempV(2)^2)
with
hypot(tempV(1),tempV(2))

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeJust for fun についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by