Page 1 of 1

Problem with rotating actors

PostPosted: Sun Mar 23, 2008 1:57 pm
by Freddy
Ive tried making a game were a cannon points to the mouse, and fires when you click. The bullet (or whatever you would call it) is created relative to the actor at 0, 0. It aslo is created to have a directional velocity moving towards were the crosshair was. The problem is, when the bullet is created, it is usually located outside the barrel. It only works properly if you point it just right. How can I get around this?

Re: Problem with rotating actors

PostPosted: Sun Mar 23, 2008 2:37 pm
by edh
You may need to know what angle the cannon is aiming at and then start it at a position relative to the barrel. Or you could start the bullet from a position not at 0,0 but something near the middle of the cannon actor. I don't think 0,0 is in the center of the actor.

Re: Problem with rotating actors

PostPosted: Sun Mar 23, 2008 5:36 pm
by Freddy
edh wrote:Or you could start the bullet from a position not at 0,0 but something near the middle of the cannon actor.

If I were to do this, would the bullet actor be created relative to the cannon's current frame? For example, say the bullet was created at 0, 25. If the cannon pointed left, would that effect the starting point of the bullet?

Re: Problem with rotating actors

PostPosted: Sun Mar 23, 2008 10:45 pm
by DilloDude
No, it wouldn't. You need to add that bit in yourself.

Re: Problem with rotating actors

PostPosted: Mon Mar 24, 2008 11:35 pm
by Freddy
Darn. How could I do that?

Re: Problem with rotating actors

PostPosted: Tue Mar 25, 2008 1:05 am
by DilloDude
Add this to global code:
Code: Select all
double xdist(double angsize, double dist)
{
    return cos(degtorad(angsize)) * dist;
}

double ydist(double angsize, double dist)
{
    return sin(degtorad(angsize)) * -dist;
}


To get the x coordinate (relative to the centre):
Code: Select all
xdist(<angle you want to use>, <radius of circle>);

y coordinate is the same, with ydist instead. So, it might be
Code: Select all
double xpos = xdist(dir, 100);
double ypos = ydist(dir, 100);
CreateActor("bullet"...  xpos, ypos, false);

or something like that. You may need to add some to those values if the centre of rotation is not the centre of the actor. Also, if the cannon rotates with an eliptical path (because of some isometric angle to the camera or something) use different values for the distances in xdist and ydist.