• Create Account

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

### #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);

}


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:

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>
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.36057671904563904, "perplexity": 10120.625594193356}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-52/segments/1418802765002.8/warc/CC-MAIN-20141217075245-00056-ip-10-231-17-201.ec2.internal.warc.gz"}