Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Some questions about collideSprites...

    Beginners
    8
    37
    1714
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      Maxwello F @vinicity last edited by

      @vinicity I think it's more a case of,
      The function checks to see if 2 things are colliding. So what it returns is the position of those 2 things. Sprite a and b.. Or piggy one and piggy two if that is preferred. You just need a name to store it within.
      That's what I think that is anyway.

      1 Reply Last reply Reply Quote 0
      • Dave
        Dave Fuze Team last edited by Dave

        You've actually caught Fuze at a bad time with that particular function page. There are errors on that page which really hurt.

        I'll post here what is going to be included in an upcoming update to the help. This is what collideSprites() does:

        collideSprites()

        Description
        Determine if two sprites have collided and optionally resolve the effect of the collision on their movement

        Syntax

        c = collideSprites( spriteA, spriteB )
        
        c = collideSprites( spriteA, spriteB, resolve1, resolve2 )
        

        Arguments

        spriteA
        Handle - Variable which stores the first sprite in the collision

        spriteB
        Handle - Variable which stores the second sprite in the collision

        resolve1
        Integer - True (1) if the first sprite can be moved by the collision, false (0) if not

        resolve2
        Integer - True (1) if the second sprite can be moved by the collision, false (0) if not

        c
        Array - List of structures detailing collision data. Properties listed below

        c.exists
        Integer - True (1) if collision occurred, false (0) if not

        c.a
        Handle - Variable which stores the first sprite in the collision

        c.b
        Handle - Variable which stores the second sprite in the collision

        c.resolution_a
        Vector - How sprite A was pushed during the collision { x, y }

        c.resolution_b
        Vector - How sprite B was pushed during the collision { x, y }

        vinicity 1 Reply Last reply Reply Quote 2
        • vinicity
          vinicity F last edited by

          Thanks a lot!
          Much more helpful than the current help page...

          Dave 1 Reply Last reply Reply Quote 1
          • vinicity
            vinicity F last edited by

            And just to confirm, c.a holds the same sprite as spriteA, and same for c.b and spriteB? This is just to make it convenient when processing the results?

            Dave 1 Reply Last reply Reply Quote 0
            • Dave
              Dave Fuze Team @vinicity last edited by

              @vinicity It'll be updated soon. In fact, I can tell you that a lot of big improvements to the help pages formatting and readability will be coming too :)

              Until then, the incredible people on this website will put you right, I'm sure!

              I'd also be happy to look at your specific case in detail.

              1 Reply Last reply Reply Quote 1
              • Dave
                Dave Fuze Team @vinicity last edited by

                @vinicity That is correct.

                1 Reply Last reply Reply Quote 1
                • vinicity
                  vinicity F last edited by

                  Thank you very much! Looking forward to the updated documentation!

                  1 Reply Last reply Reply Quote 0
                  • DomDom
                    DomDom F last edited by

                    This post is deleted!
                    vinicity 1 Reply Last reply Reply Quote 1
                    • vinicity
                      vinicity F last edited by vinicity

                      I did some more experimenting and it turns out that the c.resolution vectors are quite useful for implementing sprite bounce. I just normalized the vector and multiplied it with the desired velocity.

                      In my main loop I have two nestled for loops in order to monitor each possible collision with any two ships. So the collideSprite method is called 2450 times for each update(). For 50 ships this is pretty smooth, but if I increase the number of ships further, slowdown occurs... Kind of interesting.

                      Feel free to check out my little demo of 50 bouncing spaceships!
                      ID: NBYUXMND5C

                      1 Reply Last reply Reply Quote 3
                      • vinicity
                        vinicity F @DomDom last edited by

                        @DomDom said in Some questions about collideSprites...:

                        Collisions have 2 phases. Detection and Response. On first inspection, the collisionsprite function looks like it handles detection and provides the necessary info (in the form of the vectors you're talking about) to enable the programmer to implement the response as he sees fit. This would imply that you need to set the resultant velocities yourself.

                        Thanks, I gave it a try!

                        DomDom 1 Reply Last reply Reply Quote 0
                        • DomDom
                          DomDom F @vinicity last edited by

                          This post is deleted!
                          vinicity 1 Reply Last reply Reply Quote 1
                          • vinicity
                            vinicity F @DomDom last edited by

                            @DomDom said in Some questions about collideSprites...:

                            @vinicity Hope it helped.
                            By the way, checking collisions between 50 ships would only need 1250 checks if each ship only tests for collisions with the ships that are after it in a list.
                            Eg. something like
                            for sA=0 to Len(shipslist)-1
                            for sB= sA+1 to Len(shipslist)
                            C= checkcollisions(sA,sB)
                            Repeat
                            Repeat

                            Something else that might speed things up is to do a simple proximity check before the collision check.

                            Great point! I did not think of that, but in my defence I was kind of tired last night when I did the programming. Thanks!

                            1 Reply Last reply Reply Quote 0
                            • vinicity
                              vinicity F last edited by

                              So I made a few changes and optimizations, and cleaned up the code. Fifty bouncing ships makes for a nice screensaver...

                              1 Reply Last reply Reply Quote 0
                              • vinicity
                                vinicity F last edited by

                                I just shared a new version of my 50 bouncing ships demo. Cleaned up the code, added some optimizations to make it run smoother. Also made sure that ships that disappears at one edge are moved over to the other.

                                ID: NBYUXMND5C

                                1 Reply Last reply Reply Quote 1
                                • vinicity
                                  vinicity F last edited by

                                  After some tweaking and with a proximity check in place, I managed to get 92 ships bouncing around without dropping from 60 fps! Success!

                                  1 Reply Last reply Reply Quote 4
                                  • Dave
                                    Dave Fuze Team last edited by

                                    Awesome job @vinicity !

                                    I'm glad to hear the info was helpful. Looking forward to seeing what you make in the future!

                                    1 Reply Last reply Reply Quote 0
                                    • vinicity
                                      vinicity F last edited by

                                      Thanks! I am actually turning this into a game. I'll keep you posted once I got something new to show...

                                      1 Reply Last reply Reply Quote 1
                                      • vinicity
                                        vinicity F @Dave last edited by

                                        @Dave said in Some questions about collideSprites...:

                                        You've actually caught Fuze at a bad time with that particular function page. There are errors on that page which really hurt.

                                        I'll post here what is going to be included in an upcoming update to the help. This is what collideSprites() does:

                                        collideSprites()

                                        Description
                                        Determine if two sprites have collided and optionally resolve the effect of the collision on their movement

                                        Syntax

                                        c = collideSprites( spriteA, spriteB )
                                        
                                        c = collideSprites( spriteA, spriteB, resolve1, resolve2 )
                                        

                                        Arguments

                                        spriteA
                                        Handle - Variable which stores the first sprite in the collision

                                        spriteB
                                        Handle - Variable which stores the second sprite in the collision

                                        resolve1
                                        Integer - True (1) if the first sprite can be moved by the collision, false (0) if not

                                        resolve2
                                        Integer - True (1) if the second sprite can be moved by the collision, false (0) if not

                                        c
                                        Array - List of structures detailing collision data. Properties listed below

                                        c.exists
                                        Integer - True (1) if collision occurred, false (0) if not

                                        c.a
                                        Handle - Variable which stores the first sprite in the collision

                                        c.b
                                        Handle - Variable which stores the second sprite in the collision

                                        c.resolution_a
                                        Vector - How sprite A was pushed during the collision { x, y }

                                        c.resolution_b
                                        Vector - How sprite B was pushed during the collision { x, y }

                                        It would be nice if the collideSprites() help page could be updated with the info above, since the info that is there now is not really helpful. I know you guys are super busy, but this is just a friendly reminder so you do not forget it!

                                        waldron 1 Reply Last reply Reply Quote 0
                                        • waldron
                                          waldron F @vinicity last edited by

                                          @vinicity i only figured the sprite collision thing last week, before i was just using true/false didn't know you could link events triggers ect been a big 1 -UP for my code since

                                          vinicity 1 Reply Last reply Reply Quote 0
                                          • vinicity
                                            vinicity F @waldron last edited by

                                            @waldron said in Some questions about collideSprites...:

                                            @vinicity i only figured the sprite collision thing last week, before i was just using true/false didn't know you could link events triggers ect been a big 1 -UP for my code since

                                            Link events triggers? That sounds interesting. Care to elaborate a bit?

                                            waldron 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post