# Throwing an object in perspective (I have working code, but needs tweeking)

**URL:** <https://forum.kirupa.com/t/throwing-an-object-in-perspective-i-have-working-code-but-needs-tweeking/178370>\
**Category:** flash\
**Created:** [February 9, 2006, 10:17pm UTC](https://forum.kirupa.com/t/throwing-an-object-in-perspective-i-have-working-code-but-needs-tweeking/178370 "2006-02-09T22:17:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fishbellyrust](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/fishbellyrust/32/784_2.png) [@fishbellyrust](https://forum.kirupa.com/u/fishbellyrust)\
**Post date:** [February 9, 2006, 10:17pm UTC](https://forum.kirupa.com/t/throwing-an-object-in-perspective-i-have-working-code-but-needs-tweeking/178370/1 "2006-02-09T22:17:43Z")

</div>

I have this code – below – that I borrowed for learning purposes, and I want to tweek it so that I can make the ball appear to be bouncing towards the back of a room. My idea is to increase the variable ‘radius’ after it hits a side wall while at the same time decreasing its scale. This would make the ball increasingly smaller, as well as decreasing the area it has to move around in, giving the appearance of bouncing within a room.

An FLA is also attached to this post. Thanks!

```auto
onClipEvent(load) {
    var dragging:Boolean = false;
    var vel:Object = { x: 0, y: 0 };
    var pos:Object = { x: _x, y: _y };
    var old:Object = { x: _x, y: _y };
    var radius:Number = this._width / 2;
    var movie:Object = { width: 400, height: 300 };
}

onClipEvent(enterFrame) {    
    if( !dragging ) {
        
        vel.y += _root.gravity;
        
        pos.x += vel.x;
        pos.y += vel.y;

        if( pos.y + radius > movie.height ) {
            pos.y = movie.height - radius;
            vel.y *= -_root.restitution;
            vel.x *= _root.friction;
        }
        
        if( pos.x + radius > movie.width ) {
            pos.x = movie.width - radius;
            vel.x *= -_root.restitution;
            //decrease scale and increase radius here?
            
        }
        
        if( pos.x < radius ) {
            pos.x = radius;
            vel.x *= -_root.restitution;
            //decrease scale and increase radius here?
        }
        
        if( pos.y < radius ) {
            pos.y = radius;
            vel.y *= -_root.restitution;
        }
        _x = pos.x;
        _y = pos.y;
        
    } else {
        
        old.x = pos.x;
        old.y = pos.y;
        pos.x = _x;
        pos.y = _y;
        
        vel.x = ( pos.x - old.x ) / 2;
        vel.y = ( pos.y - old.y ) / 2;        
    }
}

```
