How do I set 'realistic' bullet speed?

0 favourites
  • 8 posts
From the Asset Store
This pack contains 10 types of bullet effects, with different shapes and colors.
  • 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?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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)). ... .capx?dl=1

  • 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' ( ... 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.

  • 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.

  • The third party trace behavior would work here as well.

    It can simulate bounces.

  • 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

  • Yes.

  • Yes.

    Thank you This plugin will cover all my needs.

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