Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am creating a Game similar to Fruit Ninja and I need some help regarding random motion of fruits in my game. I already created the slice effect, but there is no random motion of sprites.

share|improve this question
4  
It would be helpful if you explained your research efforts, what you've tried so far, what problems you've run into, and so forth. Are you struggling with the concept of how to move sprites? How to generate random vectors? Etc. – Cameron Fredman Mar 14 at 20:25
Asking again doesn't make it better... gamedev.stackexchange.com/questions/51031/… – Byte56 Mar 14 at 20:50

closed as not a real question by Byte56, Sean Middleditch, bummzack, Tetrad Mar 15 at 23:46

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

1 Answer

I would start by generating the random starting position of the item. This should be off-screen, which can be handled with a simple set of nested if statements.

Next I would generate a random direction on the screen. To make sure it will shoot onto the screen, find a random position on the screen and calculate the direction (x and y amounts, similar to slope) from the starting point and target point.

Once you have a position and direction, then you just need to give the objects a velocity proportional to the direction vector. Every frame you will decrease the y velocity to simulate gravity and the object will travel in an arc.

This is a fairly simple algorithm, although you might need to change the target point, specifically changing the y value to a high location.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.