• Create Account

### #Actualfastcall22

Posted 23 February 2013 - 07:12 PM

(The problem is partially solved for vertical directions only).

This is because you're only updating one of the two components; the Y component:

sprite.move(0,-missile->getVelY()*refreshRate);

You'll need to also include the X component:
sprite.move(missle->getVelX()*refreshRate, missle->getVelY()*refreshRate);

Of course, wouldn't it be easier to set the velocity when the rocket is created instead of having UpdateMissiles decide how they should behave?

To decide the velocity for a missile, it's a simple X=R*cos(angle), Y= R*sin(angle).

EDIT:

if(missile->getType() == Missile::Player){
// Missile angle of player is only vertical
sprite.move(0,-missile->getVelY()*refreshRate);
} else {
// This part needs to change from vertical to angles of 45,90,135 degrees
// sprite.move(0,missile->getVelY()*refreshRate);
}


This code is a bit of a code smell. If you want to have a variety of rocket behaviors, you may want to consider inheritance here.

### #1fastcall22

Posted 23 February 2013 - 07:09 PM

(The problem is partially solved for vertical directions only).

This is because you're only updating one of the two components; the Y component:

sprite.move(0,-missile->getVelY()*refreshRate);

You'll need to also include the X component:
sprite.move(missle->getVelX()*refreshRate, missle->getVelY()*refreshRate);

Of course, wouldn't it be easier to set the velocity when the rocket is created instead of having UpdateMissiles decide how they should behave?

To decide the velocity for a missile, it's a simple X=R*cos(angle), Y= R*sin(angle).

PARTNERS