jeudi 5 janvier 2017

Curve By Code how do i do it with this code?

I am trying to curve the movement of a ball. This code moves the object straight and spins the object, but it does not move in a curve motion.

if (this.ballstart.hitTestObject(this.back)) {
    trace("Hit back");
    trace("ballstart rotation: " + this.ballstart.rotation);
    removeEventListener(Event.ENTER_FRAME, update);
    addEventListener(Event.ENTER_FRAME, BowlingScoreClass);

} else {
    trace("move to back");
    this.ballstart
    this.ballstart.rotation -= -30;

    //trace("this ballstart rotation: " + this.ballstart.rotation);

    this.ballstart.y = this.ballstart.y - speed;
    speed = 15;
    /*speed = speed + 0.01;*/

    if (this.ballstart.y < -height) {
        x = Math.sin(this.ballstart.rotation * (Math.PI / 180)) * speed;
        y = Math.cos(this.ballstart.rotation * (Math.PI / 180)) * speed * -1;
        this.ballstart.x += x;
        this.ballstart.y += y;
    }
}

For non-AS3 coders, understand that the above code runs during the display's refresh function (via FPS) of my project. Here .rotation simply rotates an object on its own axis. I need to control ballstart.x and ballstart.y to make a curve motion.

Also this code will move in a v motion but i want a smooth cure how do i change it to do this? i need to curve in the top code?

if (sprite.y > 500) {
    trace(height);
    sprite.y -= 4;
    sprite.x += 4;
} else if (sprite.y > 400) {
    trace(height);
    sprite.y -= 4
    sprite.x += 2

} else if(sprite.y > this.height) {
    sprite.y -= 4
    sprite.x -= 2

}

Aucun commentaire:

Enregistrer un commentaire