Need help getting a child object to orbit a parent object ...

Started by
18 comments, last by RoyP 11 years, 3 months ago

Or, I think your can comment out this line of code and try once :

childShipRotationRadians += MathHelper.ToRadians(15);

Advertisement

That's not going to do anything. Those are just the center points on the actual textures themselves so I can rotate the texture around the texture's center point instead of the top left corner. They have nothing to do with world space. The coordinates that deal with the ship positions in world space are childShipPositionPoint and parentShipPositionPoint.

Roy

Northwest Arkansas Game Developer Group
Live in Fayetteville, Springdale, Bentonville, or Rogers?
Interested in making video games and having fun?
Check us out on Meetup.

Or, I think your can comment out this line of code and try once :

childShipRotationRadians += MathHelper.ToRadians(15);[/quote]

That just rotates the texture itself, so commenting it out just keeps the child ship pointing straight up. It doesn't affect it's position in world space, so the child ship is still rotating around the 0,0 world origin.

Roy

Northwest Arkansas Game Developer Group
Live in Fayetteville, Springdale, Bentonville, or Rogers?
Interested in making video games and having fun?
Check us out on Meetup.

Sorry bud, can't help out much unless I can figure out the exact outcome you desire.

You're telling me that this code will do this and that code will do that, where I am expecting that this is what you're looking for.

Well, I tried my best and gave you the exact concepts to solve the problem.

ow you might have to do some digging on your own and build up on the solution yourself.

Goodluck!

Let me try explaining exactly what I'm trying to do. I might not be making it as clear as I thought.

Here's an image showing what I'm trying to do:

33ngf2t.jpg

The purple ship is the parent ship. The orange ship is the child ship.

1 - I'm starting with a parent ship at (640, 320) in world space (center of the view port). I set the child ship's position with an offset of (-47, -47) from the parent ship's position. Both ships start with a rotation of 0 degrees (I convert all the degrees to radians with the MathHelper.ToRadians method). The only thing I do with the rotation amount is to use it for the SpriteBatch.Draw call in the game's Draw method and use it to pass the rotation value to the Matrix.CreateRotationZ method.

2 - When I hit the right arrow, I want to rotate the parent ship 15 degrees clockwise and compute the new center point for the child ship in relation to the parent ship. The goal is to have the child ship rotate with the parent ship while maintaining it's position within the fleet. (My eventual goal is to turn the concept into a waypoint system so I can park different child ships at the waypoints.)

3 to 7 - I need to repeat step 2 over and over again, so that the child ship keeps orbiting the parent ship while maintaining it's fleet formation. I want it to orbit in a complete circle.

When I press the left arrow key, I want to do the same thing, but in the counter clockwise direction.

Does that make it any clearer?

I know that I need to use matrix transformations to do it, but I need help understanding how to actually do the matrix transformations. I've never done it before and I need someone to walk me through it step-by-step so that I can learn what I'm doing.

I have a basic understanding of matrix and vector math, but I'm having trouble applying the abstract concepts to a concrete implementation in XNA.

Roy

Northwest Arkansas Game Developer Group
Live in Fayetteville, Springdale, Bentonville, or Rogers?
Interested in making video games and having fun?
Check us out on Meetup.

What you have to do is transform the difference vector between parent and child, not the child position itself.

Rotations matrices always rotate about the origin, so the easiest thing is to (temporarily) change your coordinate system so the parent ship's position is the origin:


Vector2 d = childShipPositionPoint - parentShipPositionPoint;
d = Vector2.Transform(d, Matrix.CreateRotationZ(15));
childShipPositionPoint = parentShipPositionPoint + d;

Let me know if this is what you are looking for.

It might be just me, but even now, the snapshot that you have provided and your problem statement seem to be complementing each other.

In simple words, I think you're trying to achieve what you already have in this snapshot.

Perhaps, an altered snapshot with expected behaviour might help.

It might be just me, but even now, the snapshot that you have provided and your problem statement seem to be complementing each other.

In simple words, I think you're trying to achieve what you already have in this snapshot.

Perhaps, an altered snapshot with expected behaviour might help.

The snapshot shows the expected behaviour. He wrote that the parent ship rotates about the origin instead.

Oh I see now. My bad for being blind there.

Can you try to write your own CreateRotationZ method? Check out this post -- http://www.gamedev.net/topic/636093-2d-camera-transformation/

@FromShadow ... you are a genius. :-) It does exactly what I needed. Thanks for explaining it to me and providing the code to do it.

@NewDisplayName ... thanks for trying to help. I appreciate it.

Roy

Northwest Arkansas Game Developer Group
Live in Fayetteville, Springdale, Bentonville, or Rogers?
Interested in making video games and having fun?
Check us out on Meetup.

This topic is closed to new replies.

Advertisement