2
votes

I'm currently in the process of making a game. he game consists of the player operating a robot from a top down perspective. The movement, collisions and firing is all implemented.

However, the robot has 2 'arms' from which it fires its weapons, to fire from these arms i have basically set up 2 makeshift locations for the robot to fire from, one for each arm, consisting of an offset in the X direction of +/- 15. When the player is looking down the arms shoot fine and the bullets appear to be coming out from the robots arms, however, when i turn the player to look to the left or right on the Y axis, it appears as though the robot is shooting the bullets from within its body. I have an image to help illustrate the issue

http://imageshack.us/photo/my-images/694/problemrs.png/

As you can see, the left and right projectile spawn points are in the correct position until the robots body is rotated. What i want to be able to do, is rotate those 2 Vector2 positions around alongside the robots body. The red blocks show where the projectiles are spawning from, and the white blocks represent where i would like the spawn position to be. I've tried a few rotation methods but none have had the effect im after.

Any clues?

3

3 Answers

4
votes

You could do it with an affine transform... but, in your case, it might be easier to do it with basic trig.

LET X, Y be the location of the robot.

LET T be the angle of rotation of the robot.

LET DX be the distance from the center of the robot to the "arm". (use -DX for the other arm).

ArmX = (cos(T) * DX) + X

ArmY = (sin(T) * DX) + Y

1
votes

I suppose, you have a forward direction and a center for your robot, then

 F = forward vector
 c = center point
 d = distance from center to arms

 NF = normal to forward

 NF = new Vector2(F.Y, -F.X);

 NF.Normalize();

 LeftArmShootOrigin = c + NF * d;
 RightArmShootOrigin = c - NF * d;
0
votes

It looks like you're rotating the vectors themselves correctly. The part you're missing is that you need to encode the position of the base/tail of your vector (the place it starts from) as a vector and rotate that as well.