How to get the angle for a parallel line?

0 favourites
  • 9 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • Angle() gets you the angle from object to object. That gets you a vector straight at the object.

    I want to get one object to travel parallel to another.

  • angle()+90 ?

  • Not quite. That's almost perpendicular.

    May have to go at it a different way.

    The second object would be in motion as well.

    So I may have to think in terms of its angle.

  • Ok look at it another way.

    You have two objects that form two parallel lines, or slopes when you get the angle between the two.

    An axis of points for each.

    Suppose one object goes up or down its axis/slope, then angle() would change.

    How would I get the new angle for the few pixels difference?

    I mean in theory I could cast the new points using trig, and angle() from those points but that seems like overkill.

  • Guess I’m confused by what you’re describing as well. A diagram could probably make it clearer.

    Instead of an angle from one object to another, you’d like the angle from one object to the other if the other moved forward a bit?

    Or maybe you mean the two objects are both moving at the same angle. They’d be moving along parallel lines then. I’m not sure what you want to calculate though. A diagram should make it clearer though.

  • I might not be understanding either, but could you just get the angle the first image is traveling at and do a set position to sin(angle -/+ offset) * distance + sprite1.x and a cos(angle -/+ offset) * distance + sprite1.y?

    I’m doing this in my head so it may not quite work that way.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The line circled in blue.

    The premise is that projectiles at the same angle, and the same time will be at the same point, and overlap.

  • It’s still not 100% clear but I’ll give it a shot.

    So I’m guessing you have an object moving along the top line left to right, and you want a second object to be on the line below, so that both objects will hit the right yellow line at the same time while moving in parallel?

    If that’s the case set the second object’s speed and angle of motion to be the same as the first. Then you can either do

    Object2: set position to object1

    Object2: move 32 pixels at angle self.bullet.angleOfMotion+90

    Or you can do:

    Object2: set position to (object1.x+cos(self.bullet.angleOfMotion+90)*32, object1.y+sin(self.bullet.angleOfMotion+90)*32)

    Where the 32 is the pixel offset.

  • Well the objects could be moving in any direction. Although in practice this probably not be the norm.

    The yellow lines indicate the parallel lines at the time the angle() (redline) was taken.

    The yellow lines would be the axis, or slope where other objects would be created.

    Then their angles would be set to the offset of the other objects axis. A perpendicular of the parallels.

    This also lets projectiles go toward the object, but not to it.

    Possible ai to get behind the object.

    But yeah, looks like the sin cos method would be best.

    Thanks guys.

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