# How do I match velocity

Get help using Construct 2

### » Thu Jul 06, 2017 8:44 am

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.

https://www.dropbox.com/s/61b6r2rqdvol3 ... .capx?dl=0
B
23
S
11
G
4
Posts: 69
Reputation: 3,439

### » Thu Jul 06, 2017 2:35 pm

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:
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

### » Fri Jul 07, 2017 7:11 am

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.
B
23
S
11
G
4
Posts: 69
Reputation: 3,439

### » Fri Jul 07, 2017 7:31 am

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
B
23
S
11
G
4
Posts: 69
Reputation: 3,439

### » Fri Jul 07, 2017 8:47 am

B
33
S
18
G
29
Posts: 2,493
Reputation: 21,450

### » Fri Jul 07, 2017 9:45 am

99Instances2Go wrote:That is absolutely weird.

https://www.dropbox.com/s/1pk3jnj629uwt ... .capx?dl=0

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

I thought this would be simple hah
B
23
S
11
G
4
Posts: 69
Reputation: 3,439

### » Fri Jul 07, 2017 10:19 am

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 ?
B
33
S
18
G
29
Posts: 2,493
Reputation: 21,450

### » Fri Jul 07, 2017 10:52 am

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.
Last edited by skrotar on Fri Jul 07, 2017 11:00 am, edited 1 time in total.
B
23
S
11
G
4
Posts: 69
Reputation: 3,439

### » Fri Jul 07, 2017 10:53 am

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
B
23
S
11
G
4
Posts: 69
Reputation: 3,439

### » Fri Jul 07, 2017 11:01 am

@skrotar

https://www.dropbox.com/s/mxz4j28nuy36d ... .capx?dl=0

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
B
23
S
9
G
4
Posts: 510
Reputation: 4,437

Next

### Who is online

Users browsing this forum: Kyledfrank, mekonbekon, troxx and 65 guests