User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11

Thread: Spread Values Enemy Gravity?

  1. #1
    Clicker Fusion 2.5 DeveloperiOS Export Module
    ChrisBurrows's Avatar
    Join Date
    May 2011
    Location
    Tasmania, Australia
    Posts
    622
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Spread Values Enemy Gravity?

    Hello,

    I am working on a side scrolling platformer. I am using multiple instances of the same active object for the enemies, each made unique using the spread values method. Each enemy has a gravity detector which is an active object "always" positioned below the enemy.

    All I want to happen is when the enemy is too far above the ground, move it down, and when it is too far below the ground move it up. I actually have it working fine BUT it is much too inefficient for my liking. Done with too many lines of code and with too many constantly looping fastloops.

    Any examples or suggestions would be helpful and very appreciated!

  2. #2
    Clicker Multimedia Fusion 2SWF Export Module
    Jacob's Avatar
    Join Date
    Jul 2007
    Location
    Second pixel to the right
    Posts
    3,208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You shouldn't need IDs for this at all. Create a value named YSpeed. Add to YSpeed

    (GroundHeight-Y("Enemy"))/100.0

    where GroundHeight is the height you want the ground at, and Y("Enemy") is the Y value of the object you are moving. /100.0 will make the gravity stronger if you pick a lower value, and smaller if you pick a higher one.

    Then set the Y Position to

    Y("Enemy")+round(YSpeed("Enemy"))

    where YSpeed is the value you just created, on the object you are doing this for. This will make the object accelerate towards the ground depending on how far away they are from it, and in which direction. In the case it propels the enemy away from the ground, change the 'Add to YSpeed' to 'Subtract from YSpeed', or change it to (Y("Enemy")-GroundHeight)/100.0.
    Your enemies should all work properly without referencing IDs, since they are only dealing with themselves and you aren't using loops.

    Hope this helps!

  3. #3
    Clicker Fusion 2.5 DeveloperiOS Export Module
    ChrisBurrows's Avatar
    Join Date
    May 2011
    Location
    Tasmania, Australia
    Posts
    622
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help Jacob! but I already figured it out and in only 4 lines of code. But...... I am still using a fastloop.

    Are you saying GroundHeight is a variable which you define manually, like say 400. Therefore all enemys will use y=400 for their ground? Or do you have a way to work out the ground height depending on backdrop objects below an enemy?

    My game has hills all over the place...

  4. #4
    Clicker Multimedia Fusion 2SWF Export Module
    Jacob's Avatar
    Join Date
    Jul 2007
    Location
    Second pixel to the right
    Posts
    3,208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, I was assuming flat ground. You would need a way to determine the ground height at a specific X coordinate, then. If your hills are constant, then you could just use something like amplitude*sin(x) to get the height, but that is likely not the case.

  5. #5
    Clicker Fusion 2.5 DeveloperiOS Export Module
    ChrisBurrows's Avatar
    Join Date
    May 2011
    Location
    Tasmania, Australia
    Posts
    622
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yeah not the case I am afraid, I got random hills and other obstacles everywhere. This is how I'm doing it:

    Each enemy has a gravity detector, an invisible active object 1 pixel thick always positioned below the enemy. It is the red line in the picture.



    1. IF a detector is NOT overlapping a backdrop obstacle, THEN run the "Gravity" loop as many times as there are enemies.
    2. On the "Gravity Loop" while an enemies detector is NOT overlapping a backdrop obstacle, THEN move the enemy down 1 pixel.
    3. IF an enemy IS overlapping a background obstacle, THEN move the enemy up 1 pixel.

    This works perfectly and is very smooth. The loop is only run when an enemy is too far above the ground as to minimise CPU usage.

  6. #6
    Clicker

    Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Jun 2006
    Location
    Killeen, TEXAS
    Posts
    1,062
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    gravity loop could be anything but number of enemies shouldnt be the factor.
    ie; run loop 100 (or even height of playfield) times.
    on loop "gravity"+ red line overlapping backdrop -> stop loop "gravity"

    eg the way you currently have it; if your object was 20 pixels about ground, and you have 5 enemies, then the loop would have to trigger 4 times/cycles before it reached the ground - rather than just the 1 time i suggested.

  7. #7
    Clicker Fusion 2.5 DeveloperiOS Export Module
    ChrisBurrows's Avatar
    Join Date
    May 2011
    Location
    Tasmania, Australia
    Posts
    622
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The loop runs ONCE for each enemy. If during the loop, the enemy at that particular LoopIndex is not overlapping backdrop then it is moved down a pixel.

    For example:
    On loop 1 check enemy 1
    On loop 2 check enemy 2
    On loop 3 check enemy 3

    If there are still gravity detectors not overlapping the backdrop, the loop is repeated.

    This way the loop is only run (and repeated) while there are enemies above the ground.

  8. #8
    Clicker

    Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Jun 2006
    Location
    Killeen, TEXAS
    Posts
    1,062
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    you need a loop to cycle through all enemies, and another loop to move them instantly to the ground.

    this will move them all down at the same time in the one cycle, rather than move them all down 1 pixel each cycle.

    having less lines in your code is not going to make it more efficient - especially when you're doing it the way you are.

  9. #9
    Clicker Fusion 2.5 DeveloperiOS Export Module
    ChrisBurrows's Avatar
    Join Date
    May 2011
    Location
    Tasmania, Australia
    Posts
    622
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I don't want enemies to instantly teleport to the ground whenever they are above it. Gravity doesn't work that way. This way, the enemies fall when they run off a ledge.

    I really appreciate when people help me on these forums and I really hope people appreciate when I help them, but you are a dick. You have no idea how I have coded my game or how it works or how I want it to work. We are all here to learn and to share knowledge and usually it isn't that hard to be polite about it. I hope your house burns down.

  10. #10
    Clicker Fusion 2.5+ DLCMultimedia Fusion 2HTML5 Export Module
    Kentronisk's Avatar
    Join Date
    Nov 2011
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im not quite following all in this thread... Im not sure if you solved your problem, and Im not even sure what Danjo did wrong :P But Im gonna stay out of it...

    Anyway, Im trying to use ForEach loops as much as possible instead of FastLoops, since I have witnessed a GREAT lag-difference between those two. Im not too technical, but if I get it right, lag = too much CPU, which means ForEach loops reduces CPU usage greatly. It was probably due to my bad programming too, but you should check it out anyway.. If the use of CPU is one of the main questions in this thread

Page 1 of 2 1 2 LastLast

Similar Threads

  1. How to make use of spread values?
    By blub in forum Multimedia Fusion 2 - Technical Support
    Replies: 12
    Last Post: 11th March 2012, 01:30 PM
  2. Bug? spread values
    By Pineapple in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 18th January 2012, 08:47 PM
  3. How are spread values spread ?
    By rudy in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 6th December 2011, 08:15 PM
  4. Enemy Gravity
    By Atherton in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 18th May 2009, 12:53 PM
  5. Spread Values-- can't get it to work!!!
    By alxmrg in forum Multimedia Fusion 2 - Technical Support
    Replies: 6
    Last Post: 3rd February 2009, 09:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •