Problem with rotating actors

Non-platform specific questions.

Problem with rotating actors

Postby Freddy » Sun Mar 23, 2008 1:57 pm

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?
Hola
User avatar
Freddy
 
Posts: 548
Joined: Sat Jun 02, 2007 3:42 pm
Location: Why do you want to know?
Score: 14 Give a positive score

Re: Problem with rotating actors

Postby edh » Sun Mar 23, 2008 2:37 pm

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.
User avatar
edh
 
Posts: 233
Joined: Thu Sep 13, 2007 12:17 am
Location: Maine, USA
Score: 14 Give a positive score

Re: Problem with rotating actors

Postby Freddy » Sun Mar 23, 2008 5:36 pm

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?
Hola
User avatar
Freddy
 
Posts: 548
Joined: Sat Jun 02, 2007 3:42 pm
Location: Why do you want to know?
Score: 14 Give a positive score

Re: Problem with rotating actors

Postby DilloDude » Sun Mar 23, 2008 10:45 pm

No, it wouldn't. You need to add that bit in yourself.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Re: Problem with rotating actors

Postby Freddy » Mon Mar 24, 2008 11:35 pm

Darn. How could I do that?
Hola
User avatar
Freddy
 
Posts: 548
Joined: Sat Jun 02, 2007 3:42 pm
Location: Why do you want to know?
Score: 14 Give a positive score

Re: Problem with rotating actors

Postby DilloDude » Tue Mar 25, 2008 1:05 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron