How do I set 'realistic' bullet speed?

Get help using Construct 2

Post » Mon Jun 19, 2017 3:30 am

I am making 'realistic' game and making everything to the scale, like 100px is equal to 6 feet. In this case, the pistol bullet speed (~1,000 feet/s) is equal to ~20,000 px/s thus making the collision check impossible. How do I use 'realistic' numbers in my game?
B
16
S
6
G
1
Posts: 23
Reputation: 1,707

Post » Mon Jun 19, 2017 10:10 am

If you really really need to track the bullets movement every frame one solution would be as follows. Don't use a bullet sprite for checking for collision. Use a sprite acting as a ray. Invisible ray if you wish, for collisions visibility is irrelevant. You can still have the actual bullet spawned and visible, only the logic of the game will not care what happens to it. Although personally if it is moving 333 pixels per frame as I just calculated, I would not bother with the bullet itself as nobody will see it anyway. I have a project on a similar scale and I just show bullet trails and assume the travel time is instant (so hitscan basically), then again I do not need actual bullet movement as everything is turn based and dicerolls pre-determine the hit/miss before the bulletrail is created.

Anyway, here is a solution to your problem, capx at the bottom:

Spawn a ray object when a bullet is fired. For a ray you need a sprite with an origin at x=0 and y equal to the middle of its height. On spawning, set its angle to the firing direction.

First you calculate how much the bullet would move during the frame. Then you draw a ray from the beginning of its path (its x and y positions) in the current frame to its end. This is done by calculating how much distance the bullet will travel this frame (dt*speed per second in pixels) and setting the ray's width to that distance. That way you will have a sprite covering the whole path travelled by the bullet during the frame (basically what a regular bullet sprite would skip over and not collide).

Next you check for collisions using the "object is overlapping another object" condition, you pick the instance of the object the ray collided with that is closest to the frame origin point. Do whatever hit logic you want with it (damage dealt, destroy sprites etc.). Destroy the ray and bullet unless you wish to make a Quake railgun or something.

If there are no collisions, you set the ray's position to its end. That is x=x+(width*cos(angle)) and y=y+(width*sin(angle)).

https://www.dropbox.com/s/mt21w5foq4v2o ... .capx?dl=1
B
15
S
6
Posts: 85
Reputation: 1,195

Post » Mon Jun 19, 2017 4:45 pm

Message: ankas can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Pulstar, thank you. I did this with a visibility and fade out effect, and it produced cool looking laser or bullet trace. Another option is to use 'Laser tutorial' (https://www.scirra.com/tutorials/588/ho ... er-for-tds).

Unfortunately both ways solve only part of my problem, because I am making a platformer game, thus requiring the 'bullet/laser/trace' do not penetrate solids and bounce off from them, making the solution too complicated, from my point of view.
B
16
S
6
G
1
Posts: 23
Reputation: 1,707

Post » Mon Jun 19, 2017 5:31 pm

@ankas

I haven't looked at Pulstar's example, but couldn't you use "Line of sight" to test if there are obstacles in the way or not? If there is no line of sight, then it is a miss, if there is line of sight, then use Pulstar's method...

Also, Construct 3 adds a "step" feature that allows fast moving bullets to detect solids.
B
95
S
33
G
20
Posts: 438
Reputation: 17,640

Post » Mon Jun 19, 2017 5:52 pm

The third party trace behavior would work here as well.
It can simulate bounces.
Image ImageImage
B
169
S
50
G
170
Posts: 8,292
Reputation: 108,728

Post » Mon Jun 19, 2017 6:04 pm

newt wrote:The third party trace behavior would work here as well.
It can simulate bounces.

Can you be more specific, please? Are you talking about jcw_trace (raycast) plugin? (plugin-jcw-trace-raycast_t172320). This plugin looks very promising
Last edited by ankas on Mon Jun 19, 2017 6:18 pm, edited 1 time in total.
B
16
S
6
G
1
Posts: 23
Reputation: 1,707

Post » Mon Jun 19, 2017 6:13 pm

Yes.
Image ImageImage
B
169
S
50
G
170
Posts: 8,292
Reputation: 108,728

Post » Mon Jun 19, 2017 6:19 pm

newt wrote:Yes.

Thank you :D This plugin will cover all my needs.
B
16
S
6
G
1
Posts: 23
Reputation: 1,707


Return to How do I....?

Who is online

Users browsing this forum: tarek2, Yahoo [Bot] and 20 guests