Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript 1.0/2.0 (http://www.flasher.ru/forum/forumdisplay.php?f=93)
-   -   Физика шара (http://www.flasher.ru/forum/showthread.php?t=195906)

DoctorQueb 15.03.2013 16:24

Физика шара
 
Вложений: 1
Привет!

Помогите создать имитацию того, что шар действительно "катится" по земле, а не просто движется.
Большая часть кода уже написана, осталось доделать только это.

Нужно что-то химичить с _rotation, но как правильно не могу въехать.

Код AS1/AS2:

xVel = 5;
yVel = 5;
gravity = 1.2;
fr = 0.7;
radiusH = ball._height/2;
radiusW = ball._width/2;
angle = 10;
 
shakeI = 50;
oldShakeI = shakeI;
shaking = false;
 
ball.onEnterFrame = function()
{
yVel += gravity;
this._x += xVel;
this._y += yVel;
if (this._y>=Stage.height-radiusH)
{
 this._y = Stage.height-radiusH;
 yVel *= -1;
 if (yVel<=-10)
 {
        shaking = true;
        createParticles(int(Math.random()*50)+1,this);
        createSmoke(30,70,this);
 }
 else if (yVel<=-20)
 {
        createParticles(int(Math.random()*5)+1,this);
        createSmoke(5,70,this);
 
 }
}
if (this._y<=0+radiusH)
{
 this._y = 0+radiusH;
 yVel *= -1;
}
if (this._x>=Stage.width-radiusW)
{
 this._x = Stage.width-radiusW;
 xVel *= -1;
}
if (this._x<=0+radiusW)
{
 this._x = 0+radiusW;
 xVel *= -1;
}
};
}

Заранее спасибо за помощь!

Tails 15.03.2013 17:56

Вложений: 2
Примерно так:

Код AS1/AS2:

var speed:Number        = 0.2;
 
onEnterFrame = function() {
        moveBall(ball1);
        moveBall(ball2);
        moveBall(ball3);
}
 
function moveBall(clip){
        clip._x                        += speed;
        var p:Number                = (1 / (clip._width * Math.PI)) * speed;
        clip._rotation                += 360 * p;
}

circle-move.swf   (4.0 Кб)

Hauts 15.03.2013 18:04

Можно _rotation привязать к _x * некий коэффициент. В простых случаях хорошо подходит.

DoctorQueb 15.03.2013 18:54

Цитата:

Сообщение от Tails (Сообщение 1125395)
Примерно так:

Код AS1/AS2:

var speed:Number        = 0.2;
 
onEnterFrame = function() {
        moveBall(ball1);
        moveBall(ball2);
        moveBall(ball3);
}
 
function moveBall(clip){
        clip._x                        += speed;
        var p:Number                = (1 / (clip._width * Math.PI)) * speed;
        clip._rotation                += 360 * p;
}

circle-move.swf   (4.0 Кб)

Спасибо большое) А что за формула такая?
Код AS1/AS2:

(1 / (clip._width * Math.PI)) * speed;

?

Tails 15.03.2013 19:01

DoctorQueb,
Нахождение процента изменения ротации от длины прокатившейся дистанций.

http://upload.wikimedia.org/wikipedi...rolled-720.gif

DoctorQueb 15.03.2013 19:08

Вложений: 1
Отлично! Теперь то, что надо!


Часовой пояс GMT +4, время: 14:22.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.