Cannon Explosion Effects Won't Sync with it's tip (rotation constraint problem)

delorianhayzedelorianhayze Member Posts: 55
edited September 2012 in Working with GS (Mac)
Hey all! Quick question. I've got a cannon that rotates (like the hands of a clock). When I fire the cannon I want the explosion effect (actor) to be constrained to the tip of the cannon. I've got an attribute that registers the cannon's Launch Angle in case that helps.
Thanks so much!

Comments

  • 3itg3itg Member, PRO Posts: 382
    I used @Tshirtbooths tutorial on Orbiting around an Object to help me sort out these types of calculations.
    I couldn't find the exact answer to my questions, but the part where he goes over sin and cos is what helped me get my weapons firing correctly.



  • delorianhayzedelorianhayze Member Posts: 55
    Thanks! This really helped out! I'd like to share with the community the answer to my question as help for others. Here goes...

    REFERENCE:
    My game has a cannon. Rotates around like a clock hand. I wanted an explosion effect to shoot out from the tip of the cannon.
    So the I had a CANNON actor and a EXPLOSION actor.
    First thing you want to do is gauge how many pixels the explosion actor is from the center point of the cannon to the tip point. In my case it was 180. So that's the number I'll be referencing here. Obviously please substitute in your own value. Also a heads up I have a REAL attribute called "CANNONangle." This attribute is a vectortoangle value of the cannon's direction via the users tap on screen (i.e. the cannon follows the angle of the user's finger on screen).

    THE CODING:
    When user fires cannon SPAWN ACTOR-EXPLOSION
    I set everything to SCENE (relative to:)
    Direction: 0
    Postion X: 180*cos(CANNONangle%360)+self position x
    Position Y: 180*sin(CANNONangle%360)+self position y
    The self position x and y are in reference to the Cannon's object self position

    Hope this helps!
  • 3itg3itg Member, PRO Posts: 382
    Glad I could point you in the right direction :)
Sign In or Register to comment.