Help with math stuff

May 13, 2007 07:36

We're doing our first major(-ish) game project and I've got a problem.

In my game, I have a number of objects flying around and at various times, I need to destroy an object and spawn 2 others that fly off at an angle (each at a different angle) from the parent's direction of travel. I'm lead to believe that right angles are going to be the easiest so I'm happy to do that. Any given object has:
- Xpos
- Ypos
- Xspeed
- Yspeed
- radius (in pixels, none larger than 64)

I think I've got the new X and Y speeds for the two child objects worked out, they should be:
- Child1.Xspeed = -Parent.Xspeed
- Child1.Yspeed = Parent.Yspeed
- Child2.Xspeed = Parent.Xspeed
- Child2.Yspeed = -Parent.Yspeed

What I can't work out is the initial positions for the two child objects. The two children will have the same radius and when spawned they need to be just far enough apart that they won't collide again.

Anyone got any idea how I do it? I don't need the detail of exactly how it works (although feel free if you want to give it :), at this stage I really just need the two formulas.

It's been well over 20 years since I've had to deal with this stuff and while it's vaguely familiar, I can't remember any details. I'm going to have to do a hunt for some tutorials and learn this all over again, but right now I don't have time as the project's due in three days and I've still got lots to do. If today were a class day, I'd ask our tutor and he'd explain it but as it's not, waiting until tomorrow would just delay the project and I wouldn't get it done in time.

Help. Please.
Previous post Next post
Up