# Velocity issue

**URL:** <https://forum.kirupa.com/t/velocity-issue/314763>\
**Category:** Uncategorized\
**Created:** [October 7, 2010, 11:40pm UTC](https://forum.kirupa.com/t/velocity-issue/314763 "2010-10-07T23:40:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbo](https://avatars.discourse-cdn.com/v4/letter/t/7feea3/32.png) [@tbo](https://forum.kirupa.com/u/tbo)\
**Post date:** [October 7, 2010, 11:40pm UTC](https://forum.kirupa.com/t/velocity-issue/314763/1 "2010-10-07T23:40:15Z")

</div>

The following code moves a ball down a slope with appropriate gravity based on the angle. What i am trying to do is apply the velocity vector to a new slope once encountered but i cant figure it out.

```auto

var slope:Number=.2;
var g:Number=9.81*40;//40 pixels per meter 
var ball:Shape;
var dt:Number=1/30;//delta time 
var v:Point = new Point();//velocity 
QuickTests();
function QuickTests() {
    stage.align=StageAlign.TOP_LEFT;
    stage.scaleMode=StageScaleMode.NO_SCALE;
    addEventListener( Event.ENTER_FRAME, onEnterFrame );
    ball = new Shape();
    ball.graphics.beginFill( 0, 0.5 );
    ball.graphics.drawCircle( 0, 0, 10 );
    addChild( ball );
    ball.x=ball.y=100;
    graphics.clear();
    //draw a line segment to show the platform graphics.lineStyle( 1, 0xff00000 ); graphics.drawCircle( 100, 100, 3 );      
    graphics.lineStyle( 1 );
    graphics.moveTo( 100, 100 );
    graphics.lineTo( 100 + Math.cos( slope ) * 500, 100 + Math.sin( slope ) * 500 );
}

function onEnterFrame( event:Event ):void {

    var normal:Point=new Point(Math.sin(slope),- Math.cos(slope));
    var reaction:Number=Math.sin(Math.PI/2-slope)*g;

    v.x += ( normal.x * reaction ) * dt;
    v.y += ( g + normal.y * reaction ) * dt;

    ball.x+=v.x*dt;
    ball.y+=v.y*dt;
}

```

if i were to say the ball encountered an opposite slope at mid screen like so:

```auto

    if (ball.x>=stage.stageWidth/2) {
        slope=-.2;
    }else{
        slope=.2;
    }

```

i want to apply the current velocity to that slope so it rolls up it until eventually rolling back down again. If someone would please help or point me in the right direction that would be great.

thanks

to give proper credit, the code is from:  
[http://www.actionscript.org/forums/showthread.php3?t=231243](http://www.actionscript.org/forums/showthread.php3?t=231243)
