如何创造漩涡/漩涡效果? [英] How to create whirlpool/vortex effect?

查看:243
本文介绍了如何创造漩涡/漩涡效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在作为传感器的圆形体上产生涡旋效果。
我一直在寻找这个,我寻找的所有例子都是用C ++或Objective C编写的,我似乎没有很好地翻译它们。

Im trying to make a Vortex effect on a Circle Body that is a Sensor. I've been looking for this and all examples i look for are in C++ or Objective C and i dont seem to translate them well.

当我的对象collition,它调用beginContact(..)并设置一个标志,以便我可以调用bodyToUpdate.applyForce(...);

when my objects collition, it calls beginContact(..) and it sets a flag so that i can call bodyToUpdate.applyForce(...);

 public void beginContact(Contact contact) {
             setColliding(true);
 }

 //updating collition every frame
 public void act(){
     if (colliding) {
        ball.getBody().applyForce(....);

 }

如何计算每帧应用的力量让它成为一个漩涡?

how to calculate the amount of force to apply every frame to make it a vortex?

编辑:

所以我现在有了这个对象直接进入漩涡的中心,但没有旋转

so i now have the object going straight to the center of the vortex, but no "spin"

public void act() {
    if (colliding) {
        ball.getBody().setLinearVelocity(0, 0);

        ball.getBody().applyForce((portal.getBody().getPosition().x - ball.getBody().getPosition().x) * i,
                (portal.getBody().getPosition().y - ball.getBody().getPosition().y) * i,
                ball.getBody().getPosition().x, ball.getBody().getPosition().y, true);

        i++;
    } else
        i = 10;
}


推荐答案

你想实现切向力的大小朝向涡旋中心增加。

You want to implement a tangential force with a magnitude that increases towards the center of the vortex.

这是一些伪代码。

radialVector = objectPosition - vortexPosition;
tangentialVector = radialVector.perpendicularVector();

if (radialVector.length() < vortexRadius) {

    // Swirl faster when near the center of the vortex.
    // Max tangential force when distance from center is 0.
    // Min tangential force when distance from center is vortexRadius.
    forceMagnitude = map(radialVector.length(), vortexRadius, 0, minTangentialForce, maxTangentialForce);
    force = forceMagnitude * tangentialVector.normalize();
    object.applyForce(force);

}

这是一个显示矢量分量的图像:

Here's an image that shows the vector components:

为了产生漩涡效应,当物体靠近中心时,应该增加径向(Fr)和切向(Ft)力。

To create a whirlpool effect there should be increasing radial (Fr) and tangential (Ft) forces as the object moves closer to the center.

这篇关于如何创造漩涡/漩涡效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆