Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualBeerNutts

Posted 07 January 2013 - 04:29 PM

In my Smash PC game (detailed in my Old Blog, linked in my Signature), I have a smoke trail for my rocket, and it can shoot at any angle.  Although it doesn't follow, it should be the same deal.

 

Here's the code I use to lay down a smoke (which quickly fades out):

 

 
    // If we're drawing smoketrails, then lay one down, and set it to fade out
    if (mbSmokeTrail)
    {
        cpVect Loc = mpBody->p;
        GameLevel::tLevelItem LevelItem;
        LevelItem.ItemName = "Smoke";
 
        // Set location at back of bullet
        Loc.x -= cos(mpBody->a)*mpImage->GetWidth()/2;
        Loc.y -= sin(mpBody->a)*mpImage->GetHeight()/2;
        LevelItem.Location = Loc;
        LevelItem.ImageName = ""; // get it from xml
        SmashPcItem *pSmokeItem = new SmashPcItem(mGameData,
                mpApp, LevelItem, mpSpace);
 
        mGameData.AddActiveItem(pSmokeItem);
    }
 
Basically, I get the center location of the rocket (cpVect Loc = mpBody->p;) Then I take the sin and cos of the angle of the rocket and multiply it by 1/2 the length (which would put it at the end of the rocket), and subtract value from the rocket Location (where mpBody->a is the angle of the rocket in radians and mpImage is the image of the rocket):

Loc.x -= cos(mpBody->a)*mpImage->GetWidth()/2;
Loc.y -= sin(mpBody->a)*mpImage->GetHeight()/2;
 
Now Loc points to the back of the rocket, regardless the angle it is facing.
 
Here's an image of the rocket being fired with the smoke trail behind it:
SmokeTrails.png
 
Good Luck!

#1BeerNutts

Posted 07 January 2013 - 04:27 PM

In my Smash PC game (detailed in my Old Blog, linked in my Signature), I have a smoke trail for my rocket, and it can shoot at any angle.  Although it doesn't follow, it should be the same deal.

 

Here's the code I use to lay down a smoke (which quickly fades out):

 
</p><div>    // If we're drawing smoketrails, then lay one down, and set it to fade out</div>
<div>    if (mbSmokeTrail)</div>
<div>    {</div>
<div>        cpVect Loc = mpBody->p;</div>
<div>        GameLevel::tLevelItem LevelItem;</div>
<div>        LevelItem.ItemName = "Smoke";</div>
<div> </div>
<div>        // Set location at back of bullet</div>
<div>        Loc.x -= cos(mpBody->a)*mpImage->GetWidth()/2;</div>
<div>        Loc.y -= sin(mpBody->a)*mpImage->GetHeight()/2;</div>
<div>        LevelItem.Location = Loc;</div>
<div>        LevelItem.ImageName = ""; // get it from xml</div>
<div>        SmashPcItem *pSmokeItem = new SmashPcItem(mGameData,</div>
<div>                mpApp, LevelItem, mpSpace);</div>
<div> </div>
<div>        mGameData.AddActiveItem(pSmokeItem);</div>
<div>    }</div>
<div>
 
Basically, I get the center location of the rocket (cpVect Loc = mpBody->p;) Then I take the sin and cos of the angle of the rocket and multiply it by 1/2 the length (which would put it at the end of the rocket), and subtract value from the rocket Location (where mpBody->a is the angle of the rocket in radians and mpImage is the image of the rocket):

Loc.x -= cos(mpBody->a)*mpImage->GetWidth()/2;
Loc.y -= sin(mpBody->a)*mpImage->GetHeight()/2;
 
Now Loc points to the back of the rocket, regardless the angle it is facing.
 
Good Luck!

PARTNERS