How do I rotate isometric turret ?

0 favourites
  • 6 posts
From the Asset Store
Simple resize and rotate events for any sprite, quick and easy event sheet that you can use for your own projects.
  • HI GUYS, I don't get it...I tried so many things... You can see my turret with 36 frames...it should animate every 10 degrees...and shoot in the direction of the target...please help ! <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile"> thanks

    capx is here : https://lookaside.fbsbx.com/file/tank%2 ... 4873gcm58k

  • The current Turret behaviour can't use frames to animate the rotation.

    You will have to do the rotation yourself.

    Take a look at this .capx:

    Download .capx

    The bullet angle is a bit off, but we could correct that with a dictionary or some advanced calculations.

    (If you want, I can show you how)

    (By the way, your initial Animation strip missed a frame between 24 and 25, I replaced that with a duplicate of 24 to correct the calculations. And I also corrected the origin of the bullet sprite, it was a bit off)

  • thanks a lot 4 ur great help!

  • edited: nevermind the solution was already posted ... by randomly

    by the way what is the ? meaning in the angle formula you used never seen it before in C2.... what the expression mean?

     aimAngle > 0 ? aimAngle : (18+(18-abs(aimAngle)))[/code:5jp73zi6] 
    
    and im reffering to the [code:5jp73zi6]0 ? aimangle : [/code:5jp73zi6] part of it
    
    Edited2: found the manual expression but still want to understand your code
  • aimAngle > 0 ? aimAngle : (18+(18-abs(aimAngle)))[/code:vqkqin9w]
    Actually, that looks complicated, but what it does, is simple.
    
    The thing is:
    In my .capx, I use the [b]angle expression[/b] to determine the way the turret has to look and, thus, which animation frame to use.
    A problem with the [b]angle[/b] expression is that it doesn't return the angle from 0-360, but from 0-180 and from -180-0.
    Look at this (notice how the angle goes negative and decreases when it should stay positive and increase):
    [img="http://i.giphy.com/3o6ZtcK4c943yreacM.gif"]
    
    Now, to use the variable [i]aimAngle[/i] for the animation frames, it needs to have the range 0-360 (because the animation frames go from 0 to 36), not 0-180 & -180-0.
    
    That's why I need to convert [i]aimAngle[/i] to a positive value each time it is below 0 (i.e. negative and not usable).
    (in my .capx, the 18 actually stands for 180 degrees. Since [i]aimAngle[/i] is already the normal angle divided by 10, it's 18 in the code. But I'll refer to 180 in the following since everything else is easier to understand then)
    
    Since you now know what the [b]?[/b] does, I'll only look at [b](180+(180-abs(aimAngle)))[/b]
    which is the conversion from everything from -180-0 to 180-360.
    
    [u]Let's take an example:[/u]
    [i]aimAngle[/i] is -170.
    We need it to be 190 (according to what I mentioned above).
    Initial code looks like this:
     [b](180+(180-abs(-170)))[/b]
    
    First of all, we need to make the negative [i]aimAngle[/i] positive. We do so by using [i]abs[/i].
    Now, [i]aimAngle[/i] is positive and we have this: [b](180+(180-170))[/b]
    Now, we substract [i]aimAngle[/i] from 180 to get the rotation that needs to be done to go from 180 to the [i]aimAngle[/i] we want (190).
    That leaves us with this: [b](180+10)[/b]
    
    And there we go: 190 is the result, exactly what we want.
    
    I hope, I was clear enough.
    [b]Got any more questions? PM me, please, so we don't have to spam this thread with off-topic stuff. ;)[/b]
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • randomly

    i see now makes more sense learned a few things how to avoid checking negative numbers hehe, also i understand now what that

     ? :[/code:pvy8ja3c] means better and how to use properly! Thanks man.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)