Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

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


Recommended Posts

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
Link to post
Share on other sites

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.

Link to post
Share on other sites

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
Link to post
Share on other sites
2 hours ago, ryanshah said:

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

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);

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.

2 hours ago, ryanshah said:

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

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.

Link to post
Share on other sites
12 minutes ago, 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.

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.

Link to post
Share on other sites
Posted (edited)
36 minutes ago, 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.

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
Link to post
Share on other sites

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.

Link to post
Share on other sites
3 hours ago, Draco18s said:

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

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

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • I have made a custom armor piece and have given it a texture for when you hold it. I have also made a custom armor material but I dont know how to make it so that when you where the armor you see a custom texture.
    • Probably only the main block should hold all the data, that way you don't have things spread out.
    • It hasn't been changed in a long time and should be updated.  But no, it's not overly aggressive. People don't read it. Look at all the support threads. 90% of them are "okay i have this issue", no debug.log in sight.
    • I solved it by copying the .gradle folder from another laptop where it works to run the client!
    • I am currently drawing a compass to my ingame gui as follows: private static void renderCompass(MatrixStack matrixStack, int width, int height) { TextureDrawer.drawGuiTexture(matrixStack, width / 2 - 110, 10, 0, 37, 221, 14); int rot; boolean f0 = mc.player.yRot < 0.0f; if(f0) rot = -MathHelper.floor(mc.player.yRot % 360); else rot = MathHelper.floor(mc.player.yRot % 360); boolean f1 = rot > 0 && rot < 180; boolean f2 = rot <= 270 && rot >= 90; boolean f3 = rot <= 180 && rot >= 0; AtomicInteger targetAngle = new AtomicInteger(-1); mc.player.getCapability(ISkyrimPlayerDataProvider.SKYRIM_PLAYER_DATA_CAPABILITY).ifPresent(cap -> { if(cap.getCurrentTarget() != null && cap.getCurrentTarget().isAlive()) { Vector3d playerPos = mc.player.getLookAngle(); Vector3d targetPos = cap.getCurrentTarget().position(); Vector3d norm = playerPos.subtract(targetPos); double angleDir = (Math.atan2(norm.z, norm.x) / 2 / Math.PI * 360 + 360) % 360; double angleLook = (Math.atan2(playerPos.z, playerPos.x) / 2 / Math.PI * 360 + 360) % 360; targetAngle.set((int)(angleDir - angleLook + 360) % 360); } else targetAngle.set(-1); }); int targetEntityAngle = targetAngle.get(); if(targetEntityAngle > 0 && targetEntityAngle <= 90) TextureDrawer.drawGuiTexture(matrixStack, width / 2 - targetEntityAngle, 14, 105, 52, 6, 6); else if(targetEntityAngle > 90 && targetEntityAngle <= 180) TextureDrawer.drawGuiTexture(matrixStack, width / 2 - targetEntityAngle + 90, 14, 105, 52, 6, 6); if (rot == 0) { drawCenteredString(matrixStack, fontRenderer, "S", width / 2, 13, 16777215); drawCenteredString(matrixStack, fontRenderer, "E", (width / 2) - 90, 13, 16777215); drawCenteredString(matrixStack, fontRenderer, "W", (width / 2) + 90, 13, 16777215); } else if (!f0) { drawCenteredString(matrixStack, fontRenderer, f2 ? "N" : "", (width / 2 - rot) + 180, 13, 16777215); if (!f1) rot -= 360; drawCenteredString(matrixStack, fontRenderer, !f2 ? "S" : "", width / 2 - rot, 13, 16777215); drawCenteredString(matrixStack, fontRenderer, !f3 ? "E" : "", (width / 2 - rot) - 90, 13, 16777215); drawCenteredString(matrixStack, fontRenderer, f3 ? "W" : "", (width / 2 - rot) + 90, 13, 16777215); } else if(f0) { drawCenteredString(matrixStack, fontRenderer, f2 ? "N" : "", (width / 2 + rot) - 180, 13, 16777215); if (!f1) rot -= 360; drawCenteredString(matrixStack, fontRenderer, !f2 ? "S" : "", width / 2 + rot, 13, 16777215); drawCenteredString(matrixStack, fontRenderer, !f3 ? "W" : "", (width / 2 + rot) + 90, 13, 16777215); drawCenteredString(matrixStack, fontRenderer, f3 ? "E" : "", (width / 2 + rot) - 90, 13, 16777215); } } What I'm trying to do is only render the entity texture (the calls including targetEntityAngle) when it is in compass view.  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.