Cirrus, Part 1: Basic Controls and Collisions

This is the first in a series of updates for my CS184 project, now codenamed Cirrus. I constructed the ground plane as a giant quad (in reality, it extends out into infinity). The large sphere is the ‘player’ at the moment, and the small spheres are balls that you fire.

2009-05-04-12-53-40

Additionally, I implemented a quick path calculator to see where the ball would land. I had a choice of using several controls – adjusting firing angle, firing speed, or the target location – to try and determine how the ball would fly out and interact with the environment. Changing firing angles would be fairly easy to implement, but I would need to settle on a constant speed. Some consequences of this are that the ball will travel very fast even for a close target and that there is a maximum distance that the ball can travel towards. Changing firing speed is also easy to implement, and consequences include the fact that nearby targets will be hit with less speed (less realistic for a cannon) and that there is a fixed firing angle. Finally, setting a target location involves a two-dimensional control (angle and speed were both one-dimensional), but would allow for the most accurate targeting

However, setting target locations suffers from a major problem in that there are infinitely many solutions for a firing angle and speed. It is still possible to use this (you would need to use a 3rd dimension to set the firing speed or angle), but I determined that it was too much for my current project. In the end, I decided to implement a firing speed changer with a fixed angle. This part of the code shouldn’t be terribly difficult to modify, and there isn’t really a reason I picked this method over the other.

In addition, I used the initial velocity and position of the ball to create a highlighted path for the ball, assuming no collisions with anything other than the ground plane. The following images show what it looks like when you’re trying to figure out a firing solution, and the ball as it travels along that path.

2009-05-05-00-55-24

2009-05-05-00-55-27

And now we come to collisions, the coolest part of the project so far. I implemented inelastic collisions with a coefficient of restitution of 0.9 for the time being. Inelastic collisions are collisions in which the two balls travel in the correct direction but with slightly less energy post-collision (in my case, exactly 90% of the incoming energy). It’s pretty fun to see the balls bouncing around all over the screen colliding with one another. It’s a shame that my plane is infinite right now – a box would be much for fun to play with.

There was one problem that I encountered along the way, which was the fact that a ball could ‘stick’ to the top of another one. An example would be when two balls are stacked on top of one another with zero velocity. The ball on top does not roll off smoothly – in fact, it tends to stick for several seconds before finally bouncing away. The reason is that if both balls have very little energy, they will not go anywhere very fast. There is another class of physics that I do not attempt to model right now, and that is contact forces. The symptom of that is two balls on top of one another will experience a series of mini-collisions and eventually fall off, but it does not look realistic at all. For now, I will not attempt to fix this problem since I do not anticipate much stacking in my final game. There are much more interesting things to focus on for the time being.

2009-05-10-21-20-21

Balls colliding (notice no intersecting balls)

Finally, I managed to test it out on my Xbox360 successfully. Getting it set up was entirely painless, and I’m impressed by the XNA team that they managed to get remote debugging working so well. One issue that might be a problem is that I currently don’t have a wired controller, so I can’t actually test a controller with my laptop when I’m not at home. It’s sad that they no longer sell the Xbox360 wireless receiver as a standalone product; it’s bundled together with a wireless controller and you’re required to buy both for some reason (go marketing). I’m really excited to actually be able to demo on an Xbox on demo day :]

Pretty slow for a week’s worth of work (distracted by TBP mostly), so I plan to use this coming week to go all out and make this a reality rather than a concept on paper. Stay tuned for updates – shadows will be next.

Comments are closed.