0 Favourites

How do I match velocity

  • Ok i thought this would be simple but its clearly way beyond me.

    All i want to do is make it so that when a bullet is fired (hitting space bar) while the player is moving (wsad) the bullet has the same directional velocity as the player.

    In the example picture you can press w to move forward and then rotate and fire. In the picture below the red arrow is your direction of travel, you rotate and fire and the green line is the path the bullet takes. I want the bullet to be fired along the green line.

  • If I understand you correctly and you simply want the bullet to inherit the angle of motion and the speed, you can use the Custom Movement expressions of the Player.

    Like so:

    Will look like this:

  • Not quite what I meant, when you shoot your bullets It lags "behind" the player. I want it so that while you are moving towards the right but turned and shooting upward (like you do when you start shooting) for the bullet to shoot on a straight line out of the nose of the ship...

    The bullet would have to gain whatever velocity the player is moving in as well as its own.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • If you look at the picture in game in my first post.. your bullets are also following the green line while moving to the right, i'd like them to follow the blue line

  • That is absolutely weird.

  • That is absolutely weird.

    Shoots right... along the blue line... but now after the bullet is shot it follows player rotation.

    I thought this would be simple hah

  • Yeah well, there is no 'red line' in your example. Ship moves only forward. Never according that red line.

    The velocity is always in the direction of ships angle.

    So, how do you want that bullet to move ?

  • Again from that first pic, the red arrow is the direction the ship is moving. The ship has rotated to face upwards (but is still travelling to the right, along the red line). When the bullet fires it comes out of the ship and travels along the green line because it does not gain the same directional momentum as the ship.

    Its like firing a gun on a platformer while falling - Normally The bullet would just go across the screen. I would like the bullet to "fall" with the platformer while still proceeding to travel across the screen.

  • So if the ship is moving towards the right side of the screen but turns and fires towards the top of the screen (firing towards the top of the screen while still travelling to the right) the bullet should move to the right with the ship... thus firing directly ahead along the blue line

  • skrotar

    How about this?:

    Left/Right keys to rotate, Up to accelerate and Space to fire. Word of warning: there's no clamp on the ship's max speed yet, so easy on the gas

  • That's it! your a life saver! thanks!!!!!!!!

  • You're welcome I'm working on the speed clamp at the mo', I'll update you when its done.

  • skrotar updated:

    I added a little bit of deceleration to get the max speed working, so a slighty hacky solution, but barely noticeable when playing - you can probably increase the ship.decel variable (= less damping) even more and it'll still work.

    If I manage to work out a proper solution (which I think involves limiting the vX, vY separately based on max speed) I'll let you know.

  • Thanks man! that looks great

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