9 Replies Latest reply on Aug 6, 2009 7:26 AM by kglad

    Advanced Tweening Question

    bje98f Level 1

      Here is my question, I will try and explain it my best,

       

      As of now, I have my project set up so that there is a ball on the screen when the movie is started.  When a user clicks anywhere on the screen, the ball tweens to that area.  This part works fine, but now I am also trying to add boundaries to my project.  For example, a rock or tree perhaps in the middle of the stage.  I want it so that my ball will recognize these boundaries, and instead of tweening in a straight line which it is doing right now, if it runs into a boundary it will still go to the destination that the user clicks but it will have to tween around the boundary instead of tweening straight through it like it does now.  If anyone can please point me in the right direction on how this is done I would greatly appreciate it.

       

      Thanks

       

      Ben

        • 1. Re: Advanced Tweening Question
          kglad Adobe Community Professional & MVP

          unless you hard-code the location of the object(s) and hard-code the tween path(s), this will require (a little) a.i. and may not be something that you find doable.

           

          you'll need to use hittest(s) between your tweened object and the obstacles and when positive you'll need to "rewind" the current tween one cycle and create more than one obstacle avoiding tweens using the obstacles boundaries as intermediate tween points.

          • 2. Re: Advanced Tweening Question
            bje98f Level 1

            Is there a way that I can predetermine the direction of the tween so that it runs along a curve instead of a straight line if there is a boundary in the way?  Lets say that the ball is on the left middle of the screen and the user clicks on the right middle of the screen.  If there is a boundary (rock, tree, etc) directly inbetween the two objects, is there any way I can detect this boundary before I tell my ball to tween?  Then I might be able to tell it to go to the destination by following a curve that goes around the boundary instead of trying to tween a straight line and detect the boundary midway through the tweening process.  I could possibly just run a loop that says if the line still is on the border, bend the line some more until it no longer is on the boundary and then it could follow that direction.  I have no idea how to do this (mainly the boundary detection and teling the tween to follow the line that is dynamically generated) but it sounds more dooable to me than what I am trying right now.  Please let me know if you have any ideas or any websites that may be helpful here.

             

            Thanks,

             

            Ben

            • 3. Re: Advanced Tweening Question
              kglad Adobe Community Professional & MVP

              yes, all that can be done.

               

              you can use the bounding rectangle of your obstacle to create a path and you can use the non-transparent parts of the obstacle to create a path using the bitmapdata class.

              • 4. Re: Advanced Tweening Question
                bje98f Level 1

                Kglad,

                 

                Thank you for all of your help so far.  Can you please give me a more detailed explanation of how I can determine the bounding rectangle of my obstacle?

                 

                Ben

                • 5. Re: Advanced Tweening Question
                  kglad Adobe Community Professional & MVP

                  you can determine the bounding rectangle by using your knowledge of your object's reg point's location and the dimensions of your object.

                   

                  it's not possible to be more specific because it's not even clear whether you're using as2 or as3.

                  1 person found this helpful
                  • 6. Re: Advanced Tweening Question
                    bje98f Level 1

                    I am using actionscript 3.0

                     

                    I do not know the exact dimensions and locations of my objects because I plan on dynamically generating and placing them. I want this to be a game where there is a character that is controlled by the mouse and there is a randomly generated level with rock, trees, enemies etc.

                    • 7. Re: Advanced Tweening Question
                      kglad Adobe Community Professional & MVP

                      you'll know all those things when they're created.

                       

                      so, for example if you have displayobject dobj1 with upper left reg point the following function will return an array of points representing the upper left, upper right, lower right and lower left:

                       

                      function boundingRectF(mc:DisplayObject):Array{
                      // [ ul, ur, lr, ll ]
                      return [new Point(mc.x,mc.y),new Point(mc.x+mc.width,mc.y),new Point(mc.x+mc.width,mc.y+mc.height),new Point(mc.x,mc.y+mc.height)];
                      }

                      1 person found this helpful
                      • 8. Re: Advanced Tweening Question
                        bje98f Level 1

                        Thanks for guiding me in the right direction.  I will try and work on this and I will make a new post if I encounter any more problems.

                         

                        Ben

                        • 9. Re: Advanced Tweening Question
                          kglad Adobe Community Professional & MVP

                          you're welcome.