Jump to content

Rendering ring of particles around entity that faces direction of entity travel


Recommended Posts

Posted (edited)

I currently spawn a ring of particles around my entity when it is spawned, however depending on how the player is facing to cast the entity the particle ring does not always appear in front of the player. I know this is something to do with the z position (vz), but I dont 100% understand how to set it in this case. For example in some directions it appears fine, but in some the ring is effectively flipped 90 degrees so all I can see is a line of particles instead of the ring.

@Override
  public void tick() {
  if (this.world.isRemote || (this.shootingEntity == null || !this.shootingEntity.removed) && this.world.isBlockLoaded(new BlockPos(this.getPosX(), this.getPosY(), this.getPosZ()))) {
    super.tick();
    ++this.ticksInAir;

    RayTraceResult raytraceresult = ProjectileHelper.func_234618_a_(this, entity -> entity.isAlive() && entity != this.shootingEntity);
    if (raytraceresult.getType() != RayTraceResult.Type.MISS && !net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, raytraceresult)) {
      this.onImpact(raytraceresult);
    }

    Vector3d vec3d = this.getMotion();
    this.setPosition(getPosX() + vec3d.x, getPosY() + vec3d.y, getPosZ() + vec3d.z);
    //ProjectileHelper.rotateTowardsMovement(this, 0.2f);

    float f = this.getMotionFactor();

    double radius = 1.25D;
    double d0 = this.getPosX() - vec3d.x;
    double d1 = this.getPosY() - vec3d.y;
    double d2 = this.getPosZ() - vec3d.z;

    for(double angle = 0.0D; angle < 2 * Math.PI; angle += 4d / 180d * (2 * Math.PI)) {
      double vx = d0 + MathHelper.cos((float)angle) * radius;
      double vy = d1 + MathHelper.sin((float)angle) * radius;
      double vz = d2 + MathHelper.sin((float) angle) * radius;

      this.world.addParticle(ParticleTypes.SMOKE, vx, vy, vz, vec3d.x, vec3d.y, vec3d.z);
    }

    this.setMotion(vec3d.add(this.accelerationX, this.accelerationY, this.accelerationZ).scale(f));
    //this.setPosition(this.getPosX(), this.getPosY(), this.getPosZ());
  } else {
    this.remove();
  }
}

 

Edited by ryanshah
updated code
Posted

You are rotating around vector3.UP (that is, the axis that points vertically) and then doing something weird by adding the same value to Y and Z (this literally makes no sense) and what you want to do is rotate around a vector that points in the direction the player is facing.

 

https://stackoverflow.com/q/31225062

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I'm still not sure I totally understand. For reference I have updated the OP to contain the tick method so you can what posX etc. I am referencing in this question.

Posted (edited)

are you sure you understand the geometry in that code? adding sine to Z and cosine to X gives you a circle. but why are you adding anything to Y? that gives you a spiral (not a vertical one, also, but you didn't want any kind).

 

and are you sure you get the part about incrementing the angle? because that code would be much simpler if you did - you'd make a constant holding the number of particles and just divide 2pi by N.

Edited by MFMods
Posted
  On 4/29/2021 at 11:57 AM, ryanshah said:

double vx = d0 + MathHelper.cos((float)angle) * radius;

Expand  

does not equal

  Quote

double vx = d0*(d0*x + d1*y + d2*z)*(1d - MathHelper.cos(angle)) + x*MathHelper.cos(angle) + (-d2*y + d1*z)*MathHelper.sin(angle);

Expand  

same goes for the other three values.

You need to rotate around the direction of travel to get the effect you want and right now you're rotating around a fixed vector.

  On 4/29/2021 at 11:57 AM, ryanshah said:

4d / 180d * (2 * Math.PI)

Expand  

A constant, divided by a constant, multiplied by a constant times a constant.
Sounds like a constant to me. Specifically Math.PI/22.5d. Or you could just do an integer loop from 1 to 45 and multiply the loop index by that constant instead of doing a loop over a double.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
  On 4/29/2021 at 2:44 PM, MFMods said:

are you sure you understand the geometry in that code? adding sine to Z and cosine to X gives you a circle. but why are you adding anything to Y? that gives you a spiral (not a vertical one, also, but you didn't want any kind).

 

and are you sure you get the part about incrementing the angle? because that code would be much simpler if you did - you'd make a constant holding the number of particles and just divide 2pi by N.

Expand  

I am adding to Y instead of Z for the angle to have my ring appear upwards infront of the player, otherwise it just appears flat.

Posted (edited)
  On 4/29/2021 at 2:52 PM, Draco18s said:

does not equal

same goes for the other three values.

You need to rotate around the direction of travel to get the effect you want and right now you're rotating around a fixed vector.

A constant, divided by a constant, multiplied by a constant times a constant.
Sounds like a constant to me. Specifically Math.PI/22.5d. Or you could just do an integer loop from 1 to 45 and multiply the loop index by that constant instead of doing a loop over a double.

Expand  

I'll do some constant refactoring later. For now, I have the current code:

 

double radius = 1.25D;
double u = this.getPosX() - vec3d.x;
double v = this.getPosY() - vec3d.y;
double w = this.getPosZ() - vec3d.z;

for(double angle = 0.0D; angle < 2 * Math.PI; angle += 4d / 180d * (2 * Math.PI)) {
  double mod = (u * getPosX()) + (v * getPosY()) + (w * getPosZ());
  double vx = u * mod * (1d - MathHelper.cos((float)angle)) + getPosX() * MathHelper.cos((float)angle) + (-w * getPosY() + v*getPosZ()) * MathHelper.sin((float)angle);
  double vy = v * mod * (1d - MathHelper.cos((float)angle)) + getPosY() * MathHelper.cos((float)angle) + (w * getPosX() - u*getPosZ()) * MathHelper.sin((float)angle);
  double vz = w * mod * (1d - MathHelper.cos((float)angle)) + getPosZ() * MathHelper.cos((float)angle) + (-v * getPosX() + u*getPosY()) * MathHelper.sin((float)angle);

  this.world.addParticle(ParticleTypes.SMOKE, vx, vy, vz, vec3d.x, vec3d.y, vec3d.z);
}

 

But where would I include the radius of the ring?

Edited by ryanshah
updated code
Posted (edited)

vx, vy, and vz represent a unit vector. Multiply by the desired magnitude.

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
  On 4/29/2021 at 4:13 PM, Draco18s said:

vx, vy, and vz represent a unit vector. Multiply by the desired magnitude.

Expand  

Thanks for the help so far, I think I'm nearly there..

float radius = 2f;
// Get origins
double u = this.getPosX() - vec3d.x;
double v = this.getPosY() - vec3d.y;
double w = this.getPosZ() - vec3d.z;

Vector3d facing = new Vector3d(getPosX(), getPosY(), getPosZ());

for(double angle = 0.0D; angle < 2 * Math.PI; angle += 4d / 180d * (2 * Math.PI)) {
  double c = (u * facing.x) + (v * facing.y) + (w * facing.z); // constant
  double vx = u * c * (1d - MathHelper.cos((float)angle)) + facing.x * MathHelper.cos((float)angle) + (-w * facing.y + v*facing.z) * MathHelper.sin((float)angle);
  double vy = v * c * (1d - MathHelper.cos((float)angle)) + facing.y * MathHelper.cos((float)angle) + (w * facing.x - u*facing.z) * MathHelper.sin((float)angle);
  double vz = w * c * (1d - MathHelper.cos((float)angle)) + facing.z * MathHelper.cos((float)angle) + (-v * facing.x + u*facing.y) * MathHelper.sin((float)angle);
  this.world.addParticle(ParticleTypes.SMOKE, getPosX() + vx * radius, getPosY() + vy * radius, getPosZ() + vz * radius, vec3d.x, vec3d.y, vec3d.z);
}

So to my understanding, I first get the origin (0, 0, 0) and i want to do the transforms over the unit vector and then apply the vx,vy,vz offsets multiplied by the radius of the circle to the original position. However, nothing here is showing. I think I might have the wrong unit vector to use..

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Ignore shrimple, it doesn't work with Oculus. Also, enableShaders was alr true when it said that towards the end of the log. If you could also figure out why my tags are messed up that'd be cool too, but that's a later issue. https://drive.google.com/drive/folders/1ovEKDZECUCl7zZxGfpyQcS4s5PZPQyfa?usp=drive_link
    • accidental duplicate mesage cuz lag
    • https://gnomebot.dev/paste/231527759279685634/1372324909073563730/1372324908629102716 https://gnomebot.dev/paste/231527759279685634/1372320454861262908/1372320454299090996 seems like theres a registry sync error, not sure what that means though, however in an old pack i played on, i actually had a registry sync error happen whenever the world tried too save and it would suddenly stop loading chunks, is there a mod fix for this or some way too bypass registry syncing? is this a server problem? i have no issues with the pack on pc, only on my server.
    • i think the problem is the player animator library but i need it for one of my main mods is there any way i can fix this? The game crashed: rendering overlay Error: java.lang.IllegalArgumentException: Failed to create player model for default heres the crash report: https://pastebin.com/U5Wp8ysb
    • I have been an enthusiastic investor in crypt0currencies for several years, and my digital assets have been integral to my financial strategy. A few months ago, I encountered a distressing predicament when I lost access to my primary cryptocurrency walleet after clicking on an airdrop link that inadvertently connected to my walleet. The dread of potentially losing all my hard-earned funds was overwhelming, leaving me uncertain about where to seek assistance. In my pursuit of solutions, I stumbled upon ChainDigger Retrievers. From our initial consultation to the triumphant recovery of my assets, the team exhibited exceptional expertise. They provided comprehensive explanations of the recovery process, ensuring I was informed at every stage and offering reassurance during this tumultuous time. Their approach was not only meticulous but also compassionate, which significantly alleviated my anxiety. ChainDigger Retrievers unwavering commitment to resolving my issue was evident throughout the process. Leveraging their profound understanding of crypt0currency technology and digital forensics, they initiated an exhaustive investigation to trace the transactions linked to my compromised wallet. Their meticulous analysis and relentless determination were apparent as they left no stone unturned in their quest to recover my funds. After several days of diligent investigation, the team successfully recovered everything I had lost. They uncovered that the link I had clicked contained malware, which scammeers had used to infiltrate my walleet. This revelation was both alarming and enlightening, underscoring the inherent risks associated with crypt0currency transactions when proper precautions are not taken.Thanks to ChainDigger Retrievers, I not only regained everything but also acquired invaluable knowledge about safeguarding my investments. Their expertise and steadfast support transformed a daunting situation into a manageable one, and I am profoundly grateful for their assistance. I can now continue my investment journey with renewed confidence, knowing that I have a trustworthy ally in ChainDigger Retrievers. Their client satisfaction is truly commendable, and I wholeheartedly recommend their services to anyone facing similar challenges in the crypt0currency realm. With their help, I was able to turn a distressing time into a positive outcome, and I will forever be grateful for their support.  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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