How do I spawn an obj on the top edge of an angled object

  • I am trying to spawn bullet objects randomly along the top edge of a rectangular player controlled object.

    The problem is that the player controlled object can rotate a bit in each direction and is therefore at times angled. I have randomized the X coordinate to spawn the bullet at (along the player object top edge), but I am not sure what to do for the Y - it may have to deal with the slope of the angle? but I am not sure.

    I have tried to use Image points to spawn the bullets but I would rather not so that I can spawn objects at any random point along the top edge of the player object.

    Thanks in advance. I know this has been tough for me to figure out so kudos to whoever gives it a go.

  • I guess you could put an image point on each of the top corners and spawn at:

    x = lerp(player.imagepointx(1),player.imagepointx(2),random(1))

    y = lerp(player.imagepointy(1),player.imagepointy(2),random(1))

    offcourse you should choose the random number between 0 and 1 before using it inside the expression,

    that way the position will be on the line between the points..

  • You could also do it like this with the "move at angle" action.

    create bullet at (player.x, player.y)

    bullet: move player.height/2 pixels at player.angle-90

    bullet: move random(-0.5,0.5)*player.width at player.angle

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You could also do it like this with the "move at angle" action.

    create bullet at (player.x, player.y)

    bullet: move player.height/2 pixels at player.angle-90

    bullet: move random(-0.5,0.5)*player.width at player.angle

    I always love your solutions..

  • Both workable solutions. Thanks guys.

    I was embarrassed to even say what I had.. I was spawning bullets at random(1,15) image points, and then adjusting each bullets X by +/- 30.

    Anyways, now it's perfect. Thanks again you two.

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