meshocky Posted February 9, 2014 Posted February 9, 2014 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 Quote
TheGreyGhost Posted February 9, 2014 Posted February 9, 2014 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 Quote
meshocky Posted February 9, 2014 Author Posted February 9, 2014 Thanks 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 thanks Thanks Quote
TheGreyGhost Posted February 9, 2014 Posted February 9, 2014 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 Quote
meshocky Posted February 9, 2014 Author Posted February 9, 2014 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 Quote
TheGreyGhost Posted February 9, 2014 Posted February 9, 2014 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 Quote
meshocky Posted February 9, 2014 Author Posted February 9, 2014 Thanks heaps, turns out it was just that divide sign that did it , I also managed to work out how to add and EntityFX so thats all good now.. 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 Quote
coolAlias Posted February 9, 2014 Posted February 9, 2014 Bookmarking this for later - I've always wondered how to go about creating this sort of effect. Thanks to both of you! Quote http://i.imgur.com/NdrFdld.png[/img]
TheGreyGhost Posted February 9, 2014 Posted February 9, 2014 Hi Keen, glad it helped Re the maths - I learnt that stuff at school (I did maths in final year) but I did manage to find this nifty site using a couple of key words I remember... http://www.mathsisfun.com/geometry/unit-circle.html or, more complicated, here http://en.wikipedia.org/wiki/Unit_circle -TGG Quote
Recommended Posts
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.