How do I object angle relations? (315-15 makes no sense)

0 favourites
  • 3 posts
From the Asset Store
A pack contains high quality game backgrounds for 2D video games. With 15 distinct themes
  • Ho!

    I am making a game where car collisions would occur, and to accurately make them, I need to know the angle relations between car A and car B.

    Current script takes 2 angle values and if A is within range of (B-10;B+10) then the event occurs. Works fine, just like in situation 1 on the picture. HOWEVER, there is a spot in the angle system where (1-10;1+10) will not describe the angle of car B because it is 359. (shown on the illustration as situation 2)

    How do I work around this? (or How do I test whether two objects are rotated towards approx. the same direction)

  • You can use one of the angle compare conditions of the system or sprite object. They handle how angles can wrap around. You could also use the anglediff() expression or if you want the signed angle difference between angles you'd just subtract the angles and normalize the result between -180 to 180.

    like this:

    diff = a-b

    while ( diff<-180) diff +=360

    while (diff>180) diff-=360

    or this:

    angle(0,0,cos(a-b),sin(a-b))

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Omg thank you for the help.

    I'll do exactly that.

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