Applying vector X to sprite with max speed of 35

0 favourites
  • 8 posts
From the Asset Store
35 high-quality characters. This asset is perfect for a side scrolling game, or even a turn based RPG type game.
  • More questions :)

    This seems like it should be a really simple task, but I can't quite get my head around it. I am shooting a bullet at the enemy (with platform behaviour) and on collision I am applying 2000 to Vector X (to simulate the enemy being bumped backwards). At first I found this wasn't working at all, but then I noticed that Max Speed was set to 35. Once I set the max speed to 350 the enemy would be bumped back a much better looking distance and continue on their path.

    The problem is, I don't want my enemy at the max speed of 350 :)

    If I try to set the speed to 350, change the vector x to 2000, then change back to 35, it all happens too fast and the enemy does not move. If I try to set some sort of wait event, this could have unpredictable results.

    What would be a smart way of saying "Take the enemies max speed, change it to 350, apply a vector x, then when [?], change back to 35". The tricky part is the [?]. I don't quite know how to determine when to switch back to the max speed of 35. As I said, it seems simple but got confusing fast <img src="smileys/smiley12.gif" border="0" align="middle" />

  • Hey boolean.

    Just thinking out loud.

    Maybe if you made your speed a variable instead, like :

    every tick -> Set Player Speed = Player.SpeedVariable.

    Then you could add (or subtract) speed from the variable on the fly easily. As for the how to get back to the normal speed you could do a couple of things, you could have a timer that when hits a certain point (like 1 second) sets the speed back to normal. You could also set it back to normal when they hit the ground or when they have gone a certain distance.

  • You could also set it back to normal when they hit the ground or when they have gone a certain distance.

    I was thinking of something similar to this today. I'm wondering if you could set the max speed to 350, apply the x vector, then maybe do a "if movement speed is < 10, set to max speed 35'. That might work.

    I'll give it a try and see how it goes.

  • What's wrong with changing the max speed and setting it back after a 'wait' action? What's unpredictable about that?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's that I don't know how long to wait for. If I have an enemy that is supposed to be heavy, they might only get bumped back a few pixels, but another regular enemy might be bumped back many pixels. In this case, do I set the wait time to be low or high? I could make it an instance variable, but it's going to be hard to test the exact amount of time to wait for every enemy.

    This also gets tricky if another event occurs like the enemy hits some scenery. He gets pushed back, but instead of travelling the full distance (a 1.5 second wait), he hits some scenery and, with the event now taking place at 0.5 seconds, rockets forward for one second while the wait timer ticks down.

    I'm playing about with GenkiGenga's suggestion right now and so far it seems to be working well. I'm going to test it a little more then I'll post a screenshot of the event sheet.

  • So as mentioned I tried GenkiGenga's suggestion, using speed instead of distance, and it seems to work pretty well. I won't upload the whole capx as this seems like a pretty simple exercise, but here are the events if anyone is interested:

    <img src="http://i.imgur.com/QSddo.png" border="0" />

    (Oddly, "speed < 1" works, but the "On Stop" event does not.)

    Is there any other ways anyone might be aware of?

  • if your enemy always go left you can do something like:

    You set the maximum speed to 800 or higher in properties

    Bullet: On collision with enemy
      -> enemy: Set Platform vector X to 800
    Every tick
      -> enemy: Simulate Platform pressing Left
      -> enemy: Set Platform vector X to clamp(self.platform.vectorX,-15,800)

    (setting the vector X to something greater than 800 is useless since you'll just be clamped to maximum speed)

  • Oh very sneaky! Ha, that would certainly work <img src="smileys/smiley1.gif" border="0" align="middle" />

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