How do I "snap rotate" while pathfinding?

0 favourites
  • 8 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • Hi,

    So I'm working on a little (sort-of isometric) real-time strategy project. I've made a unit (tank) find and drive towards a point set by right-clicking.

    I have two objects:

    • The pathfinding object, set to invisible
    • The sprite object, pinned to the pathfinding object

    I've made 72 separate sprites of the tank to complete a 360-degree view of the tank. I've also made 72 events for every sprite, checking if the pathfinding object is between angle-1 and angle-2. (I'm sure there's a better way for doing this, but it is not something I want to worry about right now.)

    The thing is that the sprite object will rotate every 5 degrees, but the pathfinding object can rotate in decimals too, meaning that if the tank sprite is angled at 45 degrees, and the pathfinding object is angled at 46.65765748547489 degrees, it will look like the sprite is slightly sideways. The temporary solution is to check if the pathfinding object is between 2 angles, but I want to eliminate that concept and check if the object is rotated at exactly X degrees.

    EDIT: Ignore the sprites and how I've coded/made them, it's the green box in the 3rd picture I'm trying to fix.

    Here's an example:

    The numbers are the actual angle of the pathfinding object, but the sprite image is angled at 0/360.

    I want the pathfinding object to snap to 0/360.

    Here's also an example of the "slidey" movement (when moving, after rotating).

    Finally, here's an example of the misalignment because it's not the exact angle.

    My question is: Is it possible to snap the rotation of the pathfinding object, so it can only rotate towards degrees 0, 5, 10, 15, 20 etc.?

    Thanks in advance.

  • Don't Pin with the angle, but set the angle yourself, every tick, to your normalized angle.

  • Don't Pin with the angle, but set the angle yourself, every tick, to your normalized angle.

    Nevermind the sprite object, it is the pathfinding object (the green square shown in the 3rd picture) that needs to snap to angles 0, 5, 10, 15 etc. up to 355. The sprites are angled at 0, 5, 10, 15 etc. degrees, but the pathfinding object is a Construct 2 object, and it rotates at anything between 0.00000000 and 359.9999999999 degrees, and I want it to snap to certain angles.

    EDIT: If it's not the sprite object you're referring to, could you perhaps explain what you meant?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Pin position only and set the sprite-rotation through event/action?

    So something like:

    System every tick

    sprite set angle : round(pathfinder.angle/5)*5

    sprite set frame: round(pathfinder.angle/5)

    Should work if 0 degrees is frame 0, 90 degrees is frame 18 etcetera..

  • Pin position only and set the sprite-rotation through event/action?

    So something like:

    System every tick

    > sprite set angle : round(pathfinder.angle/5)*5

    > sprite set frame: round(pathfinder.angle/5)

    Should work if 0 degrees is frame 0, 90 degrees is frame 18 etcetera..

    I have pinned position only, but like I said, it's not the sprite object that is the issue. Ignore the tank sprite, it's the green box I've got an issue with. The pathfinding object is a Construct 2 object square filled with green color, practically a "vector". When I right-click on a place, it will rotate towards the point and move, and additionally rotate on its way. The angle can be changed as low as 0.0000000000000000001 degrees, but I want it to rotate 360 degrees but snaps to 5 degrees per rotation. In other words, it can only rotate in 72 directions, rather than the 1 million tiny pixels it can rotate to.

    Pay attention to the number here:

    That is the angle of the green square. What you're looking at here is 2 separate objects. 1 is the sprite object (the tank), the 2nd is the pathfinder object. I have pinned the tank sprite to position only, and through events, it checks the green square's rotation, and changes sprite frame according to the green square's angle. Don't mind the tank sprite, I know how to fix that. What I need, is that green square to snap the rotation, so it doesn't land on something like 83.546654896046809 degrees, but snaps on 80 or 85 (like the tank sprite does - but again, ignore the tank sprite). In other words, I need an exact angle, no decimals. I don't want the green square to only be rotated at an exact angle, because that's what the tank sprite is doing. But I need it to rotate at an angle, so that when it has rotated to 85 degrees, it will also move at 85 degrees.

  • > Pin position only and set the sprite-rotation through event/action?

    >

    > So something like:

    >

    > System every tick

    > > sprite set angle : round(pathfinder.angle/5)*5

    > > sprite set frame: round(pathfinder.angle/5)

    >

    > Should work if 0 degrees is frame 0, 90 degrees is frame 18 etcetera..

    >

    I have pinned position only, but like I said, it's not the sprite object that is the issue. Ignore the tank sprite, it's the green box I've got an issue with. The pathfinding object is a Construct 2 object square filled with green color, practically a "vector". When I right-click on a place, it will rotate towards the point and move, and additionally rotate on its way. The angle can be changed as low as 0.0000000000000000001 degrees, but I want it to rotate 360 degrees but snaps to 5 degrees per rotation. In other words, it can only rotate in 72 directions, rather than the 1 million tiny pixels it can rotate to.

    Pay attention to the number here:

    That is the angle of the green square. Don't mind the tank sprite, I know how to fix that. What I need, is that green square to snap the rotation, so it doesn't land on something like 83.546654896046809 degrees, but snaps on 80 or 85 (like the tank sprite does - but again, ignore the tank sprite).

    Ok..

    I'm sorry, but I don't understand why that would be important..

    But if you really, really have to, you could do it by using bullet behaviour for the movement and only use the pathfinding behaviour for the pathfinding..

    Like in this example:

    Pathfinding in circles

  • Ok..

    I'm sorry, but I don't understand why that would be important..

    But if you really, really have to, you could do it by using bullet behaviour for the movement and only use the pathfinding behaviour for the pathfinding..

    Like in this example:

    Pathfinding in circles

    Ah, well - I guess there's no logical explanation to why I want it, other than wanting to make rotation and movement look seamless. Was hoping it was possible to constrain angles.

  • >

    > Ok..

    > I'm sorry, but I don't understand why that would be important..

    >

    > But if you really, really have to, you could do it by using bullet behaviour for the movement and only use the pathfinding behaviour for the pathfinding..

    >

    > Like in this example:

    >

    > Pathfinding in circles

    >

    Ah, well - I guess there's no logical explanation to why I want it, other than wanting to make rotation and movement look seamless. Was hoping it was possible to constrain angles.

    Like I said, it is possible, when using the bullet-behaviour for the movement..

    Just setting the angle of movement of the bullet to round(bullet.movingangle/5) while moving should do it..

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)