A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: when its finsihed bouncing it carrys on going down

  1. #1
    Member
    Join Date
    Aug 2008
    Posts
    41

    when its finsihed bouncing it carrys on going down

    onClipEvent (load) {
    speed = 0;
    accel = 1;
    fric = 0.8;
    gravity = 1.5
    floor = 100;
    }


    onClipEvent (enterFrame)
    {
    speed = speed+accel
    this._y += speed;

    if(this._y > floor)
    {
    speed = -speed*fric;
    }

    }

    Hi ive wrote this and it just makes my ball movie clip bounce. when its finished the ball carrys on moving up the _y axis. How do just make it stop when the friction has taken its toll?

  2. #2
    Member
    Join Date
    Aug 2008
    Posts
    41
    Still cant get this to work. Can anyone just paste this code into movie clip and see it work and tell me why its doing what its doing when the mc has finished bouncing? for those who cant be bothered, all whats happening is this mc will bounce and then loose all its momentum, when i asume it hits 0, the mc will move slowly down the page (below what i set as the floor). i dont wnat to just paste in someone elses code i want to understand why this is doing this

  3. #3
    Member
    Join Date
    Jun 2009
    Posts
    91
    Hm. I checked it out. When the ball is at of of its lowest bounces, speed is likely to be a decimal value. Even though you make it negative, that negative isn't enough to over come the accel being added to it every time. For instance: It hits the ground with speed of 1. This becomes -.8. Add one, it is positive .2, so the ball continues going down. .2 becomes -.16, which then becomes positive .84, making the ball go down further. Make sense? What you need to do is check whether the ball's speed is 1 or less when it hits the ground. If it is, set accel and speed to zero. Of course, that value needs to be negative at times, so make sure it is over 0. The finished code is here.
    PHP Code:
    onClipEvent (load) {
        
    speed 0;
        
    accel 1;
        
    fric 0.8;
        
    gravity 1.5
        floor 
    100;
    }


    onClipEvent (enterFrame
    {
        
    speed speed+accel
        this
    ._y += speed;

        if(
    this._y floor)
        {
            if(
    speed<=&& speed >=0){
                
    accel 0;
                
    speed 0;
            }else{
                
    speed = -speed*fric;
            }
        }



Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center