Tank and Tank Turret Question.

CaptFinnCaptFinn Member Posts: 1,828
edited November -1 in Working with GS (Mac)
I have 2 images. Tank Body and tank Turret. I want the tank to spawn off screen and travel along a x axis from -30 to 1100. The tank will drive str8 down that path. But the tank turret will always point and shoot at X=512 / Y=384. Since its 2 images spawning and traveling at same speed. But 1 turns. How do I go about that. Is there a video or tutorial?

Im pretty sure i got the tank body spawn and travel along x axis from left to right figured out. Its the Tank turret traveling down same x axis but staying targeted and firing on x512/y384

Comments

  • PhoticsPhotics Member Posts: 4,172
    The Unofficial GameSalad Textbook has a tank turret tutorial.

    Basically, the turret is bolted onto the tank actor with two constraints. The rotation of the turret is independent. With the "Rotate To" behavior, you can make the tank turret face where you want.
  • CaptFinnCaptFinn Member Posts: 1,828
    i think i understand most of it but not the bolt to tank with 2 contraints
  • PhoticsPhotics Member Posts: 4,172
    Heh, that's why I wrote the book. :)
    It has lots of text and pictures to explain how things like this work.

    The turret actor's X & Y positions are constrained to the tank's X & Y position. So, the turret stays with the tank, but can rotate independently.
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    Heres what you want. First you need your to create GameAttributes for the Tank x and y

    then in your tank you need 2 constrain attributes

    Constrain Attribute game.tank.x to self.position.x
    Constrain Attribute game.tank.y to self.position.y

    Now in your turret actor you need these 3 constrains

    Constrain Attribute self.position.x to game.tank.x
    Constrain Attribute self.position.y to game.tank.y
    Constrain Attribute self.rotation to vectortoangle(self.position.x-512,self.position.y-384)

    You may need to add in an offset to your turret constrains to get it in the right place but those three behaviors should keep the turret stuck to the tank and rotated at your target.

    Hope that helps you out.

    Aaron
    ___________________________________________________________________________________
    Project Help from Tenrdrmer Click Here

    GS BubbleBall Template HERE!!
    Stacks Level Selection Template HERE!!
    Expanding Option Menu Template HERE!!
    Tenrdrmer's Menu # 3 HERE!!
    Menu #4 - Level Banners HERE!!
    AppSolute Entertainment on Facebook
    AppSolute Entertainment on iTunes
  • PhoticsPhotics Member Posts: 4,172
    tenrdrmer said:
    Constrain Attribute self.rotation to vectortoangle(self.position.x-512,self.position.y-384)

    I think the "rotate to" behavior makes more sense here.
  • CaptFinnCaptFinn Member Posts: 1,828
    k Is tankx and tanky inthe gameattributes a real or a int?
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    int should be a bit more efficient
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    You want to use real. integer only does whole numbers not decimals
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    Photics said:
    I think the "rotate to" behavior makes more sense here.

    I dont he's not moving back and forth it's just one shot across the screen as I understand so why not just constrain it so it stay locked to his target.
  • CaptFinnCaptFinn Member Posts: 1,828
    rotate to positon 512/384 didnt work
    and the vector to didnt either
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
  • PhoticsPhotics Member Posts: 4,172
    tenrdrmer said:
    so why not just constrain it so it stay locked to his target.

    It's because it's not as realistic. Tank turrets don't face their targets instantly. They turn towards their target. I also use "Rotate To" because it better handles the zero crossing.
    scitunes said:
    int should be a bit more efficient

    I usually use Real. Even for booleans, I sometimes use Real with 0 and 1 instead. The efficiency is negligible... like next to zero... but the additional options are beneficial. As an example of the tank turret, I think Real makes more sense because the rotation should be smoother, not snapping to the nearest angle.

    There is an easy way to change your mind, but it involves editing XML... something that the GameSalad Creator can get really fussy about. One mistake and your entire project can cease to function. So, to leave room for future expansion and ease of development, I usually use Real.
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    I made you a demo for the rotation part

    http://gamesalad.com/game/19826

    ___________________________________________________________________________________
    Project Help from Tenrdrmer Click Here

    GS BubbleBall Template HERE!!
    Stacks Level Selection Template HERE!!
    Expanding Option Menu Template HERE!!
    Tenrdrmer's Menu # 3 HERE!!
    Menu #4 - Level Banners HERE!!
    AppSolute Entertainment on Facebook
    AppSolute Entertainment on iTunes
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    Photics said:
    It's because it's not as realistic. Tank turrets don't face their targets instantly. They turn towards their target. I also use "Rotate To" because it better handles the zero crossing.

    True but that not what he asked for. :)
Sign In or Register to comment.