Compare Angle Dramas

This forum is currently in read-only mode.
  • For an idea I'm trying out, I need to compare whether the angle between the player and the obstacle is between two other angles. For example:

    Is angle between player and obstacle within obstacle's angle + 45 and obstacle's angle - 45

    This sort of thing works fine and dandy if I use a perfect square at an angle of 0, but I want to use squares of varying widths and heights that also have an arbitrary angle.

    Finding the angles between each corner of the square i can do, it's the comparing of the angles that messes everything up, specifically, the 180 and -180 crossover point.

    Using the 'is greater than' and 'is less than' comparisons gets stuffed when the range you're comparing crosses over the 180 mark.

    Any help on resolving my issue?

  • Using some trigonometry you can do real angle calculations, but a simplified version might just be to use the 'rotate towards...' actions in Sprite. You might be able to work out something with that...

    By chance, the next build has better angle calculation features. There's a 'rotateangle' expression which rotates an angle towards an angle. In this case, if you temporarily rotate the player's angle to the obstacle's angle with a step of 45 degrees, if it then equals the obstacle angle you're within 45 degrees. Obviously you'd need to use a separate object or store the old angle, so you don't leave it changed.

  • That might help out, thanks.

    Basically I'm trying to tell construct which side of the square my player collides with so it knows the angle at which to bounce off. The squares will be different shapes, sizes and angles so i'm trying to develop a way of finding out regardless of these factors.

  • Anyone got any ideas how to test to see if one angle is between two other arbitrary angles?

    You'd think it would easier than this :S

    stupid 180, -180 crossover....

  • Here's a cap of the problem is you don't quite get what i mean:

    http://www.mediafire.com/?zz5zzzldd1e

    WSAD to resize box, Q and E to rotate, X to reset

    Basically it works fine until you turn the dam thing cause the 180 to -180 crossover point thingy

    Any suggestions?

  • Unless you want the trigonometric calculations behind this, I think you may as well wait until the next build. There's a new 'angle is clockwise of other angle' expression, so you could test if the angle is clockwise of one angle, and anticlockwise of the other. I think that'd do the trick.

  • Those new angle things sound awesome i can't wait

    For curiousity's sake i would like to know the trig behind it, i'll most likely just dump it later for the new angle conditions, unless it's too much effort, in which case i don't mind waiting till the next build

    sweet

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here's the function, hope it's clear enough:

    // start angle, end angle, step
    float RotateTowards(float start, float end, float step)
    {
       if (step == 0) return start;
    
       float cs = cos(start);
       float ce = cos(end);
       float ss = sin(start);
       float se = sin(end);
    
       float z = cs*se - ss*ce; // for determining clockwise/anticlockwise
       float dot = cs*ce + ss*se;
       float angle = acos(dot); // angle difference between start and end
      
       if(angle > step)
          if(z > 0) // is clockwise
             return start + step;
          else // is anticlockwise
             return start - step;
       else
          return end; // angle difference is less than step - finish on end angle
    }[/code:15kakc7c]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)