Game Development Community

Change bullet axis

by Matt Roszak · in Torque Game Builder · 12/07/2009 (2:05 am) · 7 replies

I'm currently using TGB and script to get my player running around like a side scroller. When I flip my player to run in the opposite direction everything works fine excepts for the bullets. They still fire in their original direction. I know that has to do with the way I have the linearvelocity function setup. But does anyone know what I would call so the bullets know whether to move along the x or -x axis?

Thanks for any help.

#1
12/10/2009 (7:29 pm)
Can anyone help me out? I revised me question to include a little more info.
#2
12/10/2009 (7:50 pm)
You're on the right track, the function you are looking for is getFlipX(). Once you know if the player is flipped or not, you can set the linear velocity of the bullets in the positive or negative direction.
#3
12/10/2009 (7:55 pm)
Thanks, Mike. I did try that but I'm relatively new to TGB so my scripting is lacking yet. Atleast I know I'm moving in the right direction. I'll give it another shot tonight.
#4
12/10/2009 (11:00 pm)
Here is a simple example of what you might do:
function MyPlayerClass::Shoot( %this )
{
    // Facing Left.
    if ( %this.getFlipX() )
    {
        %bulletVelocity = "-10 0";
    }
    // Facing Right.
    else
    {
        %bulletVelocity = "10 0";
    }

    // Create Bullet.
    // ...
}
#5
12/10/2009 (11:22 pm)
Awesome, thank you, Philip. When I get home I'll try it out but that looks exactly like what I was trying to come up with. Much appreciated.
#6
12/11/2009 (5:11 am)
I just tried out the code you posted Philip and it worked! Thank you guys for the help, I really appreciate it.
#7
12/11/2009 (6:13 am)
You are most welcome mate, glad I could help!