Jump to content

  • Log In with Google      Sign In   
  • Create Account


Adding trailer behind a rotateable missile


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 P0jahn   Members   -  Reputation: 265

Like
0Likes
Like

Posted 07 January 2013 - 03:00 PM

So, I have a missile that is rotated every frame so it is facing the target. I want to add a trailer behind this missile. I am having trouble getting the right coordinates.

First, it looks like this:
known.png
All the coordinates of the rectangle is known at this point.
Then I rotate this missile with a known angle, and it may look like this:
unknown.png
At this point, all the coordinates to the rectangle are lost.

How do I get them?

Edited by P0jahn, 07 January 2013 - 03:03 PM.


Sponsor:

#2 BeerNutts   Crossbones+   -  Reputation: 2855

Like
0Likes
Like

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):

 

 
    // 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!

Edited by BeerNutts, 07 January 2013 - 04:29 PM.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#3 Aeramor   Members   -  Reputation: 1127

Like
0Likes
Like

Posted 09 January 2013 - 11:56 AM

This is a problem best solved by a particle engine.

For each "smoke" piece you want it should be added to the scene as its own object and at the time it is placed given its own velocity/angle etc as well as a TTL (time to live) and fade out over that time period. As soon as it "dies" it should delete itself (or you can have Particle Factory above it do the deletion) and be removed from rendering lists.

I don't recommend trying to shortcut this, this can be amazingly useful in all things game related and is a great way to learn a lot more about how you should be treating objects in games.


-Aeramor

CTO at Conjecture, Inc.


#4 P0jahn   Members   -  Reputation: 265

Like
0Likes
Like

Posted 11 January 2013 - 07:33 PM

EDIT: Never mind, the bug was elsewhere. BeerNutts suggestion works just fine. Thanks!



#5 Aardvajk   Crossbones+   -  Reputation: 5968

Like
0Likes
Like

Posted 12 January 2013 - 11:01 AM

At this point, all the coordinates to the rectangle are lost.

How do I get them?

 

Transform the base point by whatever transform you are applying to the sprite. In D3D9X-speak:

 

D3DXMATRIX m;
D3DXMatrixRotationZ(angle, &m);

D3DXVECTOR3 coord(pos.x - halfWidth, pos.y - halfHeight, 0);
D3DXVECTOR3 newCoord;

D3DXVec3TransformCoord(&coord, &newCoord, &m);

 

 

May have the parameter orders wrong there.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS