Dev Log: Laser turrets and more artwork in!

Discussion in 'Developers Blog' started by Chris, Sep 5, 2014.

  1. Chris

    Chris Well-Known Member Staff Member

    • Stardale Staff
    • Developer
    Joined:
    Mar 29, 2014
    Messages:
    157
    Likes Received:
    354
    Trophy Points:
    78
    mooCow
    I spent some time today adding laser turrets. It required a bit of math to figure out but the task was accomplished. For those who may be programmers or anyone interested, the way it works is as follows; if not, skip the next two paragraphs to continue ;).

    This works within 2d space and 3d space. First you have to calculate the distance between your starting and ending position, in this case the turret and the target. Once you have this, you can use it to set the length of how long the laser beam will be. In this particular scenario the laser has a range of 50m and as soon as a target is locked onto, it fires instantaneously at light speed - so we set the length of the laser beam to the distance between the turret and the target. Second step, calculate the angle of rotation to set the laser pointing in the right direction of the target (using Atan2 - remember in grade 10 math class? sin/cos/tan? it is actually useful in programming for those still in school). If you don't do this, your laser beam will get longer and shorter depending how far away the target is but it wont point towards the target - or anything, it will stay at a fixed angle. At this point we have set how long the laser beam should be and the angle to position it at so it looks like its going towards the target, but there's more work to do yet.

    Thirdly and finally, because right now the laser beam position is based on the centre of itself in my setup, we have to find the centre between the turret and target. Why? Because right now as I said, the laser centre when it was created is itself and because it was created beginning at the turret, it looks like a big long stick on the turret and like its shooting from two sides. When we increase the length of the laser, yes it gets longer, but because its centered on top of the turret it is increasing in size in two directions ----T---- (T is the turret, dashes are the laser) when we want it to only "seemingly" increase on one side T--------. It is still visually increasing in size on both ends but to make it look like its tracking the player and fixed to the turret, we find the centre between the two points. Since the angle is set in step two, it looks like its tracking the target perfectly. To find the centre between turret and target we use a little more math of adding the turret position + target position then dividing by two (you could find the centre of even more points by adding them all then dividing by the total number of targets added).

    Now finally, done, the laser beam tracks and follows the target grilling them with a strong beam of radiation. All that just for one laser beam canon. :D And of course because we hate redundant code, we throw it somewhere useful so we can use it in other parts of Stardale.

    What's next? We're working on our kickstarter page and getting things ready. The laser turrets are required for one of the bosses which will be available within a video we use on our kickstarter. Kickstarter details to come when it's available, but it's going to be good and come with amazing rewards - and for some rewards, even physical items! Fancy oh lala!

    From the art dept aka Jose, he has submitted a dozen more tile sheets so we're well on our way. We have dozens of clothes, several character races, over two dozen tile types, bosses, backdrops, and more, so we're well on our way!
     
    #1
    Last edited: Sep 5, 2014
    Dezi, gnarvin, Andy and 1 other person like this.
  2. gnarvin

    gnarvin Well-Known Member

    Joined:
    Aug 7, 2014
    Messages:
    36
    Likes Received:
    29
    Trophy Points:
    68
    mooCowmooCowmooCowmooCowmooCow
    Thanks for taking the time to explain how the turret works, I love learning more about how games are designed and programmed. Keep up the awesome work!
     
    #2
    Chris likes this.

Share This Page