How to make a smooth corner turn

  • Using the behavior of the bullet and triggers, I create a model patrol, when the object touches the trigger, it is rotated 90 degrees but does so sharply, but should do so smoothly.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Probably the easiest solution would be to remove that "Set angle" action and add another event:

    On every tick: Enemies rotate 5 degrees towards Enemies.Bullet.AngleOfMotion
    

    In Russian: "На каждый тик: Enemies повернуть на 5 градусов к Enemies.Пуля.УголДвижения", что-то в этом роде :)

  • WRS

    it was a little more complicated than I expected when there were multiple patrol objects and lots of triggers. In my sample, patrols move until they hit a trigger, they then turn until they match the angle of the trigger, then start moving again.

    If a trigger is set to an angle of 90 degrees, C2 sometimes thought it was a small fraction off (like 90.00002), so you have to round the angles before comparing.

    I also ran into trouble when multiple patrols were overlapping triggers at the same time - you have to make sure you are comparing to the correct trigger.

    then, if the difference in direction is more than 180 degrees, you probably want to turn the shorter direction, so in that case the patrol turns -5 degrees.

    you can get my sample here:

    https://www.rieperts.com/games/forum/patrol.capx

    EDIT: one important note is that, obviously, if the patrol is turning 5 degrees (or -5 degrees) per tick, then you have to make sure the angle of the trigger is a multiple of 5 - otherwise the angle of the patrol will never match up with the angle of the trigger and it will just spin around on the trigger forever...

  • EDIT: one important note is that, obviously, if the patrol is turning 5 degrees (or -5 degrees) per tick, then you have to make sure the angle of the trigger is a multiple of 5 - otherwise the angle of the patrol will never match up with the angle of the trigger and it will just spin around on the trigger forever...

    I suggest using "Rotate towards" action, it will rotate the sprite correctly. Say, if the difference between angles is 3 degrees, "Rotate 10 degrees towards angle" will rotate the sprite by only 3 degrees.

    Another way to do this is with Pathfinding behavior - for each enemy find path to the next patrol point. Pathfinding will take care of sprite rotation, acceleration/deceleration etc.

  • Thank you so much guys. Already broke his head on this.

  • WRS

    it was a little more complicated than I expected when there were multiple patrol objects and lots of triggers. In my sample, patrols move until they hit a trigger, they then turn until they match the angle of the trigger, then start moving again.

    If a trigger is set to an angle of 90 degrees, C2 sometimes thought it was a small fraction off (like 90.00002), so you have to round the angles before comparing.

    I also ran into trouble when multiple patrols were overlapping triggers at the same time - you have to make sure you are comparing to the correct trigger.

    then, if the difference in direction is more than 180 degrees, you probably want to turn the shorter direction, so in that case the patrol turns -5 degrees.

    you can get my sample here:

    https://www.rieperts.com/games/forum/patrol.capx

    EDIT: one important note is that, obviously, if the patrol is turning 5 degrees (or -5 degrees) per tick, then you have to make sure the angle of the trigger is a multiple of 5 - otherwise the angle of the patrol will never match up with the angle of the trigger and it will just spin around on the trigger forever...

    The system is very difficult to work and if I just put triggers in a different order, then everything is working to work (

  • Another way to do this is with Pathfinding behavior - for each enemy find path to the next patrol point. Pathfinding will take care of sprite rotation, acceleration/deceleration etc.

    Then you have to create a lot of unique triggers?

  • Try this one:

    https://www.dropbox.com/s/eeuzglzwkdimlv3/PatrollingEnemy.capx?dl=0

    Oh, thank you very much)

    If this circle is working fine) And if this is a difficult route, then it turns in one direction. I will try to create additional triggers and turn to another side. It may help.

  • WRS

    for my sample, you can have as many triggers as you want and move them anywhere. You just have to change the angle of the trigger to point to the next one (and make sure they are lined up so that the patrol will hit the next trigger).

  • WRS

    for my sample, you can have as many triggers as you want and move them anywhere. You just have to change the angle of the trigger to point to the next one (and make sure they are lined up so that the patrol will hit the next trigger).

    Yes, I figured it out, there was a bug in the construct, and after the new load everything started working)

    Thank you very much

  • Patrolling with pathfinding:

    dropbox.com/s/nglwbuzmdjpd7os/PatrollingEnemy2.capx

  • Patrolling with pathfinding:

    https://www.dropbox.com/s/nglwbuzmdjpd7os/PatrollingEnemy2.capx?dl=0

    Thank. I will disassemble)

  • WRS

    it was a little more complicated than I expected when there were multiple patrol objects and lots of triggers. In my sample, patrols move until they hit a trigger, they then turn until they match the angle of the trigger, then start moving again.

    If a trigger is set to an angle of 90 degrees, C2 sometimes thought it was a small fraction off (like 90.00002), so you have to round the angles before comparing.

    I also ran into trouble when multiple patrols were overlapping triggers at the same time - you have to make sure you are comparing to the correct trigger.

    then, if the difference in direction is more than 180 degrees, you probably want to turn the shorter direction, so in that case the patrol turns -5 degrees.

    you can get my sample here:

    https://www.rieperts.com/games/forum/patrol.capx

    EDIT: one important note is that, obviously, if the patrol is turning 5 degrees (or -5 degrees) per tick, then you have to make sure the angle of the trigger is a multiple of 5 - otherwise the angle of the patrol will never match up with the angle of the trigger and it will just spin around on the trigger forever...

    AllanR

    hey, in your example when the angle of the object changes from 180 to 270 degrees it doesn't rotate in -2.5 degrees

    please do have a look at the capx file i am attaching below

    drive.google.com/file/d/1C0TmW-rNAlTtwJZwlciZyRpOUj0ho_kd/view

  • Sangeeth777

    it looks like C3 handles angles differently than C2 does. If the directioner angle is less than the truck_convoy_base angle, the result is a negative angle. (In C2 the result wraps around and stays in the 0 to 360 range)

    so, you need to change event 9 to make sure the comparison always stays positive. To do that add 360 and then use MOD (%) 360 to keep angle in the correct range.

    (directioner.Angle-truck_convoy_base.Angle+360)%360

    I updated my sample (for people who download it in the future), so that it works for both C2 and C3.

    https://www.rieperts.com/games/forum/patrol.capx

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