Jump to content

[1.7.10] Projectile stops in mid-air?


Ms_Raven

Recommended Posts

I have no idea why, but I can't get any of the many projectile tutorials I've tried to work. It would always either only ever go in one direction or spawn but not move at all until hit.

 

So I gave up and de-obfuscated a mod to try to figure out just what I'm doing so wrongly compared to a finished mod that I've tried and that works, and finally found some code that's successful...at first.

 

Unfortunately, after about 2 seconds of travelling, the projectile starts slowing down exponentially for another second until it stops in mid-air... I assume it's something to do with the math, but I've always been horrible at that so I really don't know what's going on there.

 

What exactly is going on here and how can I get it to just fly straight?

 

				Vec3 vec1 = player.getLook(1);
			EntityLargeFireball fireball = new EntityLargeFireball(player.worldObj);
			fireball.setLocationAndAngles(player.posX + vec1.xCoord, player.posY + player.getEyeHeight() * 0.85,
					player.posZ + vec1.zCoord, player.rotationYaw, player.rotationPitch);
			fireball.motionX = (-MathHelper.sin(fireball.rotationYaw / 180.0F * 3.141593F)
					* MathHelper.cos(fireball.rotationPitch / 180.0F * 3.141593F));
			fireball.motionZ = (MathHelper.cos(fireball.rotationYaw / 180.0F * 3.141593F)
					* MathHelper.cos(fireball.rotationPitch / 180.0F * 3.141593F));
			fireball.motionY = (-MathHelper.sin(fireball.rotationPitch / 180.0F * 3.141593F));

			fireball.motionX *= 2.0D;
			fireball.motionY *= 2.0D;
			fireball.motionZ *= 2.0D;

Link to comment
Share on other sites

Just straight? I'd look into Ghast and Blaze projectiles instead. AFAIK a large fireball is compelled to travel in a straight line by default, so you'd only need to see how a Ghast does it. I remember doing something similar in Bukkit (a fireball spell) and I don't recall any of that math present at all - just spawn the ball, apply a vector to it and go (your problem might be trynig to use motionXYZ instead of a addVector or similar method that might do the math for you).

I do pony stuff :3

Link to comment
Share on other sites

There is another set of fields called acceleration.

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 comment
Share on other sites

You're using the wrong constructor - most projectiles have a constructor that takes an EntityLivingBase, i.e. the one that is shooting the projectile, and will automatically calculate the trajectory and velocity for you. Some also have a constructor that takes the target entity which is useful for mobs shooting at players.

 

Unfortunately, EntityFireball is a bit odd in the projectile world, as Draco pointed out, but you can still use a constructor that takes more arguments for a better result. Blazes, Ghasts, etc. typically pass in the difference between the target's position and their own. From the Ghast:

double dx = this.targetedEntity.posX - this.posX;
double dy = this.targetedEntity.boundingBox.minY + (double)(this.targetedEntity.height / 2.0F) - (this.posY + (double)(this.height / 2.0F));
double dz = this.targetedEntity.posZ - this.posZ;
EntityLargeFireball entitylargefireball = new EntityLargeFireball(this.worldObj, this, dx, dy, dz);

That will create a fireball heading towards the target's current position with appropriate velocity and acceleration. Of course there are a couple extra adjustments that the ghast and such make to the position before spawning it to make sure it doesn't immediately collide with themselves, but you can see that in the code.

Link to comment
Share on other sites

I also have code here for making fireballs that are shot off based on lookvec.

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



×
×
  • Create New...

Important Information

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