Spawn random actors with predefined intervals

2»

Comments

  • Twayne2Twayne2 Member Posts: 458
    edited May 2018

    @Ciaphis said:
    I’m just going to assume that:

    I can call another actors destroy true/false from within another actor....

    Well the potential of invisible actors mixed with self.atrributes is quite powerful and can accomplish this. For example, say in actor 1 spawn invisible actor B on actor 2's position. (X,Y.) And in actor 2 say if collide with actor B, change self.atrribute A to 1. If self.attribute A is 1, destroy this actor. Thus the effect is destroying actor 2 due to actor 1's behaviors. Also this would allow you to have multiple actors of actor 2 on the screen and not all of them would get destroyed at once. (Thus the power of self.attributes.) :)

  • CiaphisCiaphis Member Posts: 58
    edited May 2018

    You guys are awesome!

    I kind of figured I could do this.

    My next question is this:

    I need to vary the speed of an actor based on time (IE... after 50 seconds change attribute self.ObjSpeed = 350)

    Or would creating a game variable “game.ObjSpeed” work better?

    In both situations the actor in question hitches for a split second when the timer runs out and continues with the original speed “300” instead of advancing to “350”.

    I am assuming at this point I need to create a game variable(Boolean) and tag each move behavior with their own game variable for the different speeds and use an if statement to turn on and off each move behavior dependent on a timer.

    I would I like to get a more drastic random Y position so the obstacles don’t spawn with say 50 pixels of the previous Y position.

    It appears that I have a bit of work yet to accomplish.

    Thanks for all of the help!

  • Twayne2Twayne2 Member Posts: 458
    edited May 2018

    To make the obstacles appear more ''drastically'' I suppose you could have a game attribute. (Let's call it game.attribute A.) The scene has a height of 1000. A starts at 0. In the spawn actor rules list, have say 5 rules. Say if A is 0, spawn the actor, (or object in this case,) from 0 to 200 pixels on the y axis relative to actor. (This means instead of basing the actors position from the scene's own y grid it varies from the actor.) Then change A to 1. If A is 1, spawn the object -500 to -300 pixels relative to actor. See? Come up with several rules and you can make the object appear random within certain spaces. If you came up with a lot of rules I suppose you could make the objects never appear next to each other. But at this point, is it really random? Not really. Random means random, even if the objects appear close to each other. :smile:

  • CiaphisCiaphis Member Posts: 58

    Explained perfectly, random is a matter of perspective and can be faked if done properly.

  • CiaphisCiaphis Member Posts: 58
    edited May 2018

    I tackled the actor (obstacle) "increase speed at timed interval" using the following method

    Create new Variable (int) in the actor to be moved

    ObjSpeed

    Created a move behavior:

    Move in Direction: 180, Relative to: Scene, at speed: self.ObjSpeed

    Created a Rule called Speed 300

    If: game.time is <= 20

    Do:

    Constrain: self.ObjSpeed to 300

    I created a total of six of these rules to step the speed of the actor from 300 to 600 by 50 in increments of 20 seconds.

    for every other attribute call, use >= as your equalizer. example:

    if game.time is <= 20
    constrain self.ObjSpeed to 300

    if game.time is >= 20
    constrain self.ObjSpeed to 350

    if game.time is >= 40
    constrain self.ObjSpeed to 400

    if game.time is >= 60
    constrain self.ObjSpeed to 450

    if game.time is >= 80
    constrain self.ObjSpeed to 500

    if game.time is >= 100
    constrain self.ObjSpeed to 550

    if game.time is >= 120
    constrain self.ObjSpeed to 600

    I had to deal with the timer behavior in the "Spawner Actor" for the following reason:

    at a speed of 300 and a timer set at every 2 seconds, the flow seems just about perfect but as you increase the speed the objects feel as if they are spawning slower. We know that this is not true but eh appearance says otherwise.

    I did the following in two rules and it works rather well:

    create rule:

    If game.time is <=40

    Do:

    Timer: every: 1.5 Seconds, run to completion

    Spawn Actor (actor name), from position X cords, Y cords, relative to scene

    else:

    Rule:

    If "game.time" is >=40

    Timer:

    every 1.0 second, run to completion

    Spawn Actor (actor name) from position X cords, Y cords, relative to scene

    This seems to be running rather good and not difficult to set up.

    *I've decided not to try and add pseudo-random Y spawn positions and instead just widen the margins in which I have them already set (Random(220,540) for spawning. A bit of tweaking will be needed to pull it together.

    I have begone work on the menu scene and am having a few issues but will eventually get it figured out - I hope

    After the menus are set, I will return to the logic part of the game to deal with score keeping, database calls (if allowed), login function, store function, level and character select and the good 'ol custom font woes that I have been reading about on these forums.

    I hope, that when I am done, I will be able to write a well rounded to the point tutorial for those that are just getting in to this program and are a bit intimidated by it.

    Thanks for all of the help guys, it has been and still is much appreciated and always welcomed!

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited May 2018

    Just a note that this:

    if game.time is >= 20
    constrain self.ObjSpeed to 350

    if game.time is >= 40
    constrain self.ObjSpeed to 400

    if game.time is >= 60
    constrain self.ObjSpeed to 450

    if game.time is >= 80
    constrain self.ObjSpeed to 500

    if game.time is >= 100
    constrain self.ObjSpeed to 550

    if game.time is >= 120
    constrain self.ObjSpeed to 600

    Can be replaced with this:

    If game.time is >=20
      constrain self.ObjSpeed to game.Time*2.5+300

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • CiaphisCiaphis Member Posts: 58

    That makes a lot of sense.

    Essentially using one if statement to control the six that I was using. I tend to do things the long winded way, need to train myself to look for methods to consolidate.

    I get a weird “hitch” when the actor moves across the screen c almost as if it hands for a split second and then continues on about its business.

    Will have to set this out over the next few days.

  • CiaphisCiaphis Member Posts: 58

    Here is a copy of the project I am working on. Go ahead and run it and see if you notice the "hitching" behavior that the "Dual Object" is performing while scrolling from Right to Left.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited May 2018

    Yes, I think so. Right about the 0:14 mark:

    Probably hard to see on YouTube but it really doesn't matter since you're seeing it in GameSalad, too. ;)

    I believe what's causing it is the multiple Constrain Attribute behaviors you have going at the same time. I didn't catch this until I saw your rules but... what you want to do (if you don't use my single constrain behavior example above instead) is to nest your conditions:

    if game.time is >= 120
         constrain self.ObjSpeed to 600
    else
         if game.time is >= 100
              constrain self.ObjSpeed to 550
         else
              if game.time is >= 80
                   constrain self.ObjSpeed to 500
    [etc.]

    That way only ONE rule condition is true at any given time and therefore only ONE constrain behavior is firing at any given time.

    Multiple constrain behaviors have a way of eating up performance really quickly.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • CiaphisCiaphis Member Posts: 58

    I tried plugging in your single rule but it didn’t work for me and I was heading out the door to c Me to work.

    I will give it a go when I get home.

  • CiaphisCiaphis Member Posts: 58

    I will also start setting up the collisions tomorrow. There were a few questions that Inhad pertaining to the character and how it responds with collisions but I will try and sort them out before I ask.

    Thanks again for the help!

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    You're welcome! I'm probably not the best person to ask about collisions as I tend to make apps/games that are heavy on tables, math, etc. and light on physics. But post it and someone will likely have an idea about how to help.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • CiaphisCiaphis Member Posts: 58

    The collisions shouldn’t be very difficult. The only issue I had was getting the player actor to display the death animation as soon as it collided with the scrolling obstacles. I’m sure that was born out of my “I don’t need no manuals” mentality that Inused when I first started.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    One suggestion is to spawn a new dragon actor when the collision happens and destroy the existing dragon. The new dragon actor should have its own rules (e.g. no movement, no scoring, just animation behaviors).

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • Twayne2Twayne2 Member Posts: 458

    @Ciaphis said:
    I tried plugging in your single rule but it didn’t work for me and I was heading out the door to c Me to work.

    I will give it a go when I get home.

    Did it ever work?

  • Twayne2Twayne2 Member Posts: 458

    Btw on collisions you can make it custom collisions using something like physics editor. Then collisions aren't constrained to just rectangles. I made a banana collision for a game.
    A note though is that after a free trial ,at least with the editor that I used, you would have to buy it. :wink:

  • Twayne2Twayne2 Member Posts: 458
    edited May 2018

    Good job on the progress that you've made, especially for someone with your amount of posts! :smile:

  • CiaphisCiaphis Member Posts: 58

    I get home in about an hour from work, will give it a try and post back with the results.

    Thanks @Twayne2 , i’ve Been on the asset creation side (3D modeling) side of the house for a decade and have limited experience with code, mostly the basics. I did manage to code out a terrain editor using DarkBasicPro several years ago but as with any skill, if you don’t use it, you lose it.

    Cheers

  • CiaphisCiaphis Member Posts: 58

    I own a license for phys editor and two other programs (animator) and (lighting) can’t remember the exact names of them.

  • CiaphisCiaphis Member Posts: 58
    edited May 2018

    This is what I have set for my DualObject and my Spawner. The DualObject will not spawn at all. Not sure what I am missing here, I bet it's something simple. IF it is, make me work for the answer a bit.

    DualObject:

    Spawner:

  • CiaphisCiaphis Member Posts: 58
    edited May 2018

    Got it sorted,

    I needed to set the change attribute of the DualObj:

    Change Attribute

    set: self.ObjSpeed to game.time*2.5+300

    Constrain Attribute

    constrain: self.ObjSpeed to game.time*2.5+300

    Works like a champ. I can now get rid of all those move calls.

  • CiaphisCiaphis Member Posts: 58
    edited May 2018

    I am working on the Timer for the spawner at the moment. This is what I am assuming:

    Change attribute self.SpawnSpeed to game.time (some math)
    Constrain attribute self.SpawnSpeed to game.time(some math)

    timer

    every game.time(some math) <---- spawn frequency

    am I correct in this?

    I also believe I will have to write to expressions to properly solve this issue because as the object speed increases the objects appear to spawn further apart even though the spawn rate is set to 1.5.

    I will need on to handle all spawning <=40 to 1.5 seconds and one that handles spawning >=40 to 1 second intervals.

    This is going to twist my mind for a bit as I try to wrap my brain around the math. It would be simpler if I rounded to the minute (60 second) instead of 40 seconds.

    Something like SpwnSpeed to game.time-20

    For the 1 second timer

    And

    spwnSpeed to game.time+20 for the 1.5 timer

  • CiaphisCiaphis Member Posts: 58
    edited May 2018

    removed my comment to avoid confusion

  • CiaphisCiaphis Member Posts: 58
    edited May 2018

    Removed my comment to avoid confusion

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    @Ciaphis said:
    Change attribute self.SpawnSpeed to game.time (some math)
    Constrain attribute self.SpawnSpeed to game.time(some math)

    Constrain changes the value of an attribute constantly. That's why I suggested only using one constrain behavior at a time per attribute. If you use a Change Attribute, it's going to change the value once. If you use a Constrain Attribute, it's going to change the value continuously. You don't need both behaviors.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • CiaphisCiaphis Member Posts: 58
    edited May 2018

    @tatiang

    ok, I am at a bit of a loss when dealing with timers.

    I should be able to use an If statement to get the desired result:

    if game.time <=40
    Do: timer: every 1.5
    spawnactor

    else

    if game.time >=40
    Do: timer: every 1.0
    spawnactor

  • CiaphisCiaphis Member Posts: 58
    edited May 2018

    Using the IF statement worked today but failed every other time I tried it. haha, woe is the life.

    I inadvertently added a scoring system when I displayed a timer to check the timing vs spawning precision.

    I also found a sweet, straight forward video for custom fonts.

  • CiaphisCiaphis Member Posts: 58
    edited May 2018

    Alright guys, it’s Friday, the youngin is gone for the weekend. Time for the girl and I to go cut loose. Haha let’s hope I don’t get home and try to work on this project.

  • CiaphisCiaphis Member Posts: 58

    Got the score timer working properly with the custom numbers.

    Finally something that worked the first time around!

Sign In or Register to comment.