Hi all:
I hate to post again so soon, but I have another
question:
I have this bitmap rotating at center of screen.
I want to shoot a ball from the bitmap across the
screen at the angle of the rotating bitmap. I am
pretty close but something is not right with what
I have now. I have uploaded the two files above
so you can see what I have now. It should be very
simple but in two days I haven't a clue what is
wrong. If you could point me in the right direction,
that would be great.
Thanks for your time!
Each update should be off the last x and y, not new x,y.
ball_x = ball_x + cos(angle) * speed;
And the draw should be based off the current x and y.
Save yourself some hassle and pre-convert your pi/180 or 180/pi. Just a suggestion. Saves writing time.
#define PI_OVER_180 0.017453292
Actually confused as to why you have ball_x/y and new_x/y. What is the purpose of each?
Hi Scooter, nice to see you again.
So, to clear up a few things, you're mixing ball and turret updates together. The angle of the ball shouldn't change once it is fired. Track the start x and y of the ball and get the speed * delta time with the original firing angle to get the new position.
Hi Daniel and Edgar:
Thanks for your replies!
I have posted an update using the instructions.
You can see my changes. I am now shooting the ball.
Great relief! But I still have a problem,
If I comment out 'updating the turret angle' and then press
the SPACE Key the ball will fire to the right like
it is supposed to. If I allow to turret to rotate it appears
the ball is not rotating with the angle of the turret. When
I press the SPACE Key the ball fires at a different angle.
Kinda crazy really. I still can't see what is going on! If
you run my update you will see what I mean!
No hurry, just when you have time!
Thanks for your time!!!
I know exactly what I need to do, but I can't make it happen!
If the ball is not centered on the turret, say because it's on the end, then you need to account for that. What is the length of the turret? Use trig to get the end of the turret. That is where the ball is when it has not been fired. When it is fired, store the position and angle of the ball.
Hi Edgar:
Having no luck at all today.
Did you take a look at my update I posted above?
The trouble I am having is the ball position is
not following the turret. The ball_angle should
be the same as the turret_angle which is angleX
incremented at 2 degrees converted to radians.
The turret is located at center of screen at:
x = 640
y = 360
ball location at 690
turret is 100 x 80
2D rotations have always been a problem for me!
3D rotations are NOT this big of a problem!
If you remember, some time ago I was asking about
unfolding a 3D cube. Had no problem doing that'
I will be back at it again tomorrow to see if
I can solve the problem.
Thanks for your time.
Hello Scooter, I had a play around with your code. It looked like you were updating the ball angle and new_x/y every frame, whcich I couln't really follow. Also it looked like the ball just appeared then disappeared?
I have changed some code and made a new function start_shoot_ball() that starts the ball firing when you press space.
Try my code and see if it's closer to what you wanted? I don't know if you want the ball to keep following the turret angle after firing, that seems odd but, let me know!!
Hi Dizzy:
This looks GREAT!
I finally got the ball to track the turret but I was
never able to shoot the ball with the Space Key.
The only things I changed was:
I changed the ball speed to 15.
I advanced the turret angle 10 degrees to shoot the ball.
This made the ball track the turret angle closer. I might
still be off a little on that.
Everything seems to be perfect, just what I wanted.
Great job, as usual!
Thanks, have a great day!