Change a sprite position regarding player position

0 favourites
  • 7 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • Greetings! I'm working on a vertical shoot'em up...

    My game creates some enemies.

    This enemy can generate an horizontal laser on the left, or on the right. Basically, it's the same laser, it's just changing its position and angle.

    I would like it to create and maintain the laser to the right when the player.X > enemy.X, and vice versa.

    When the player.X becomes < enemy.X, after 1 second the laser changes side.

    I managed to do that for 1 enemy, but it doesn't work well with several enemies. There are some conflict between the laser instances. I don't really know how I should associate the laser to the enemy.

    If someone can help me out regarding this issue...

    Here are my crappy events :

    <img src="" border="0" />

    And my capx :

    The event are in the enemies event sheet.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I gave the laserShip an instance variable called laserUID to keep track of it's laserShipShot.

    I like the artwork. I'm doing a breakout game in the same style (hand drawn on paper background). Though you're better at drawing than me.

  • I like the artwork aswell, nice style.

    PS: I would consider using smaller background textures if I were you, they are now 2MB out of the total game size of 2.2MB. Not much of a point using tiled backgrounds when they don't repeat. <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Thanks for your replies :)

    I hope my GF will be motivated enough to do the artwork, she's

    way better than me for sci-fi stuff. :D

    Now the actual problem is this that if your move your ship quickly to the right of an enemy, and then to the left and you do that multiples times, it will execute all the instructions and the laser will quickly change its orientation the same number of times.

    I tried to use a variable that increases periodicaly when the player X is > enemy X, and decreases periodicaly when the player X is < enemy X.

    When the variable reaches 1 or 0, the laser changes its orientation.

    Seems very, very simple (and I'm quite sure it is), but there is something I can't figure out, it doesn't work as it should be.

    Here is a test .capx with only the required sprites and instructions (and without the variable), very clear and simple :

    (If I stick on the "select nearest laser", I won't need to check UIDs I think)

    That's why I think a variable could help. If you have any idea to how fix this... :)

    edit a few hours later :

    I've made another document which visible variables on the layout :

    I don't understand why the variable "timer" perfectly works for the first enemy instance, but not for the next ones.

    Is a "for each enemy" a good start or I am wrong?

  • Looks like I'm too late, but here's my solution anyways:

    Canapin_test.capx (r93)

  • You're not too late, I was wrong and edited my post... :(

    I'm checking your solution !

  • I integrated your events in my game, it works almost perfectly. Sometimes, a ship doesn't move its laser on my side, but it's kind of rare and I can't reproduce the bug, so I'll keep it for a while.

    Thank you very much !

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