how does an Object that gets spawned by another object (same sprite) copies a spec. value?

0 favourites
  • 13 posts
From the Asset Store
A collection of various soldier character sprites for creating a 2D platformer or sidescroller game
  • Hello Dear fellow game designers, i am creating an ecosystem, an aquarium of Fishes, that evolve.

    It starts off with a bunch of fishes with a bullet speed of 100, If a Fish finds something to eat, it spawns another fish, which is the same Sprite. So there is supposed to be a Mother-Kid relation. I want the new spawned fish (the kid) to have the same bullet speed as the mother, variating by a random value about -20/+20.

    My Problem is:

    When the mother spawns the kid,

    the kid is taking the default bullet speed, which is always 100, + the random value (-20/ 20) and is not taking the one specifically of his mother as base.

    i am clueless on how to solve that problem, Here's a link to my project, i'd be really happy for help!

    optimally someone just makes it work in the event sheet and uploads the file again in this threat kek.

    drive.google.com/file/d/1Gasu-eH2AVD4E4hzXa9OWGF6neDsPu_e/view

  • You can pass the spawning sprites speed in a function variable as you call a function that picks the last created sprite and sets it's speed to the variable.

  • firstable thank you, i think i came closer to the solution,

    but i still have the problem that the spawned fish doesn't copy the speed of the "mother", but it spawns with the speedvalue 100+random(-20, 20). Instead of the 100 i need the speed of the"mother.

    this is the first time i used a function, did i do something wrong?

  • To troubleshoot, first remove your +random (0,200) expression and just set the new sprite to the function variable. This should set the new sprites speed to whatever the mother's speed was when they spawned the new sprite.

    Is this working correctly?

    Your events look correct.

  • yeah that works. (:

  • maybe i explained it a little weird

    what i want at the end is basically:

    on spawn of a fish the speed is supposted to be :Speed of Mother+random(-20, 20)

    what i got right now is :100+random(-20, 20)

  • If that works then set speed to speed+random(-20,20) is what you want.

  • I tried that now, but there is still no actual evolution over more generations.The function doesn't take the value of every individual fish, but it always takes the

    basic value which is 100.I'll give an example for the math on how it should be:

    Fish spawns on start of layout: speed=100(default speed)+random(20, -20), example: 120 speed.

    If this fish spawns another fish: speed=120(speed of mother)+random(20, -20), example: 140 speed.

    Then again if this fish spawns another fish: speed=140(speed of mother)+random(20, -20), example: 160 speed.

    Right now it is like that:

    Fish spawns on start of layout: speed=100(default speed)+random(20, -20), example: 120 speed.

    If this fish spawns another fish: speed=100(default speed)+random(20, -20), example: 120 speed.

    and that repeats forever. I hope this is somewhat understandable..

    thanks for your time and capacities <3

  • You aren't capturing the mothers speed before you create the second sprite. Store that first in a local variable, and use that for the calculation. Right now you spawn a new sprite and then send it's speed (100) to the function.

  • I'm still a beginner, i really have problems putting that together.

    could you show me how that would look like on an event sheet?

  • Add a blank subevent so you can add a local variable, then grab the parent value first, spawn, and then use that value.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The function method that I posted works as you want it to. I'm not sure what else you're doing but it works correctly for me.

  • I did as requested in the next topic, but for some reason, objects are sometimes assigned a black color (0,0,0), which is the default for this sprite. I can’t figure out what it’s connected with and where the error is in this code.

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