Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[1.7] [Solved] Spawn particles with a rotational velocity - Tornado like

Featured Replies

Posted

Hi all, first post so hopefully everything goes well.

 

Im looking into creating an item which creates a tornado like effect around the player, I have managed to spawn the particles, my only issue is getting the particles to move in around the player in a circle, like a tornado. I have looked into angular velocity and such as the spawn particle method takes in 3 velocity arguments for x, y, and z.

 

    world.spawnParticle("largesmoke", posX, posY, posZ, velocityX,  velocityY, velocityZ);

 

I am using the 1.7 gradle version of forge, however the concept should be universal.

 

Thanks

Meshocky

Hi

 

If you want the particles to move in a circle, you will need to update their velocity every tick ("speed" is not the same as velocity because velocity has a direction).  If you just provide an initial velocity they will keep going in a straight line; vanilla particles which change their direction or speed (eg due to gravity or due to slowing down) use the onUpdate method

 

So if you want your particles to swirl, I'd suggest copying the EntitySmokeFX into your own class and changing the onUpdate method to set a new motionX, Y, Z every tick, or alternatively just to set the position directly using something like

 

onUpdate() ...

++tickCount;
this.posX = this.centreX + circleRadius * Math.cos(2 * 3.141 * (tickCount / 20.0) * secondsPerRevolution);
this.posZ = this.centreZ + circleRadius * Math.sin(2 * 3.141 * (tickCount / 20.0) * secondsPerRevolution);

(You'll need to set your centreX, centreZ, circleRadius etc when you create the particle)

 

Might need a bit of tweaking but the basic idea should work...

 

-TGG

 

 

  • Author

Thanks :D ill check that out, once i've made a new ParticleFX class how do I call that in the spawnParticle method as it requires a string, or should I use spawnEntity?

 

Edit: SpawnEntity worked and is now spawning little white cubes :D thanks

 

Thanks

Hi

 

I'm pretty sure you need to create your new EntityFX

 

spawnedEntityFX = new EntityVortexFX(x,y,z etc)

 

Minecraft.getMinecraft().effectRenderer.addEffect(spawnedEntityFX);

 

I don't think you should use spawnEntity because they aren't handled the same way as effects particles.  Effects are client-side only (they don't do anything except look good) but entities are controlled by the server and if you have too many it will get very slow.

 

-TGG

  • Author

Alright well I tried creating a new ParticleFX and all....

 

public class EntityParticleFX {

public static EntityFX whirlwindFX;

 

public static void init()

{

Minecraft.getMinecraft().effectRenderer.addEffect(whirlwindFX);

 

}

 

}

 

Then in the main class for the mod I called it...

 

then in the item I tried to call it however I added a few more arguments...

 

world.spawnParticle("EntityWhirlwindDustFX", world, randPosX, randPosY, randPosZ, 0.0D, 0.0D, 0.0D, entPosX, entPosY, entPosZ, 0.5f);

 

The code button here isnt working so here is a pastebin of my new entityFXclass its just the hearts fx class but copied over, and then I tried some maths to rotate the particles, but when I used the spawnEntity method, they where kind of spinning but around a much smaller circle and they were spazzing out every tick...

 

http://pastebin.com/w56wRbx4

 

Sorry for this long winded response, Im still getting to grips with forge, and also programming in general.

 

Thanks again though

 

-meshocky

Hi

 

If you're just starting out, some of the topics on this page might be useful for background information

http://greyminecraftcoder.blogspot.com.au/p/list-of-topics.html

 

Just for an initial test I'd suggest

 

public class EntityWhirlWindDustFX extends EntityHeartFX
{
      public EntityWhirlWindDustFX(World par1World, double par2, double par4, double par6, double par8, double par10, double par12)
      {
          super(par1World, par2, par4, par6, par8, par10, par12);
       }
}

 

then in your Item add the line

      Minecraft.getMinecraft().effectRenderer.addEffect(new EntityWhirlWindDustFX(world, randPosX, randPosY, randPosZ, 0.0D, 0.0D, 0.0D, 0.5F));

 

Hopefully (once you've correctly my code syntax if necessary :-) ) this will spawn hearts when you click the item

 

Once you get this far, you can change your constructor, and start overriding various methods in your EntityWhirlWindDustFX to customise the behaviour, especially the .onUpdate()

 

Your math looks roughly right except

        this.posX = this.entityCentreX + distToCentre * Math.cos(2 * 3.141 * (tickCount / 20) * secondsPerRevolution);

should probably be

        / secondsPerRevolution);

 

Sorry, that was my fail :-)

 

-TGG

 

 

 

 

 

  • Author

Thanks heaps, turns out it was just that divide sign that did it :D, I also managed to work out how to add and EntityFX so thats all good now.. :D

 

If you don't mind me asking, where did you learn the concepts for the maths used in the rotation, just off the internet, I've  found a couple of good books on game mathematics...

 

Thanks so much

-meshocky

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.