How do I spawn objects in quantity proportionally to the car speed?

Not favoritedFavorited Favorited 0 favourites
  • 5 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • The idea is that the tank leaves track marks on the ground. With regular X second spawn objects, there is a visual problem. The slower it moves, the more objects spawn at that period of time. How can I spawn objects proportionally to tank-car speed? The faster it moves, the bigger the amount of marks that spawns. How can I convert Tank.Car.Speed to something that can be used in Every X seconds...?

    C3P

    https://www.dropbox.com/scl/fi/t1y1bllcb6jsauek2b7gk/Movement-Tank.c3p?rlkey=c9jgobg8gdz61as89mmisj95z&st=dejsostw&dl=0

  • You can utilize the formula: speed*time=distance

    And solve it for time: Time=distance/speed

    You can the set distance to whatever the spacing you want is. Maybe every 8 pixels?

    Then you’d have “every 8/speed seconds”

    I can see a few issues with that approach though. At low speeds, say 0.1 pixels per second, it will be “every 80 seconds”, or worse still at a speed of zero it will be “every infinity seconds”. You can mitigate it by limiting how big the number can be: min(0.1, 8/speed)

    A second issue is the “every x seconds” is any value less than dt will be the same as dt. So at high speeds the tracks would be spaced out more again.

    Another idea is to keep track of the previous position of the tank and and use a loop to create tracks between the previous position and the next.

    Var prevx=0

    Var prevY=0

    Var ang=0

    Start of layout

    — set prevx to sprite.x

    — set prevy to sprite.y

    Every tick

    — set ang angle(prevx,prevy,sprite.x,sprite.y)

    Repeat distance(prevx,prevy,sprite.x,sprite.y)/8-1 times

    — create track at prevx,prevy

    — track: set angle to ang

    — add 8*cos(ang) to prevx

    — add 8*sin(ang) to prevy

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Say, you want to spawn the tracks every 10px, then use this condition:

    Every (10/Tank.speed) seconds

  • I have applied very easy solutions to all the problems in your tank game.

    You can download the corrected file here: fileport.io/cPChmSHYWztN

  • Thank you guys for your help

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