Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.7.10] Projectile stops in mid-air?
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
Ms_Raven

[1.7.10] Projectile stops in mid-air?

By Ms_Raven, January 12, 2016 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Ms_Raven    2

Ms_Raven

Ms_Raven    2

  • Creeper Killer
  • Ms_Raven
  • Members
  • 2
  • 106 posts
Posted January 12, 2016

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;

  • Quote

Share this post


Link to post
Share on other sites

Zethariel    3

Zethariel

Zethariel    3

  • Stone Miner
  • Zethariel
  • Members
  • 3
  • 74 posts
Posted January 12, 2016

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

  • Quote

Share this post


Link to post
Share on other sites

Ms_Raven    2

Ms_Raven

Ms_Raven    2

  • Creeper Killer
  • Ms_Raven
  • Members
  • 2
  • 106 posts
Posted January 12, 2016

That's my point, I can't figure out how to do that...

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2090

Draco18s

Draco18s    2090

  • Reality Controller
  • Draco18s
  • Members
  • 2090
  • 13999 posts
Posted January 12, 2016

There is another set of fields called acceleration.

  • Quote

Share this post


Link to post
Share on other sites

coolAlias    745

coolAlias

coolAlias    745

  • Reality Controller
  • coolAlias
  • Members
  • 745
  • 2805 posts
Posted January 13, 2016

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.

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2090

Draco18s

Draco18s    2090

  • Reality Controller
  • Draco18s
  • Members
  • 2090
  • 13999 posts
Posted January 13, 2016

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

  • Quote

Share this post


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.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • matt1999rd
      [1.14-newer] deprecated method onBlockActivated

      By matt1999rd · Posted 1 minute ago

      okay so how can I replace it if I cannot use blockState ? I saw on other post that people in 1.14 are using onBlockActivated too and nothing is suggest to replace it in the Block class unfortunately...
    • DragonITA
      [1.14.4] Why minecraft with mod dont want start?

      By DragonITA · Posted 2 minutes ago

      i try with delete the entier Config Folder but it still dont work and the Folder come back.
    • plugsmustard
      on/off button for custom furnace

      By plugsmustard · Posted 3 minutes ago

      what exactly is wrong with them. i was told to return a new packet?
    • JetCobblestone
      [1.14] moving item assignment to a separate function

      By JetCobblestone · Posted 5 minutes ago

      Hey everyone,   I'm trying to move my item assignment into a new class. I've stuck in into the same package as my main and called it ItemsLoader.   package jetcobblestone.firstmod; import jetcobblestone.firstmod.lists.itemList; import net.minecraft.item.Foods; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.util.ResourceLocation; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; public class ItemsLoader { public static final String modid = "first_mod"; public static void Items() { @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD) public static class RegistryEvents { @SubscribeEvent public static void registerItems(final RegistryEvent.Register<Item> event) { event.getRegistry().registerAll ( itemList.hair_fibre = new Item(new Item.Properties().food(Foods.COOKIE).group(ItemGroup.FOOD).maxStackSize(1)).setRegistryName(location("hair_fibre")) ); } } private static ResourceLocation location(String name) { return new ResourceLocation(modid, name); } } }   This is the new class, however I'm running into an issue with the new Items function. It's giving me an error saying that it's expecting a volatile at the void token. Why is it trying to force me to do this? I don't want to send this to main memory? If I do replace void with volatile, it tells me there's a syntax error on the 'void' token, despite the fact there is no void. Any help would be much appreciated, thank you!
    • Draco18s
      on/off button for custom furnace

      By Draco18s · Posted 9 minutes ago

      Good. Now fix these two lines. https://github.com/drmdgg/marijuanacraft1.14.4/blob/a246b0229e61058b95672d7f4813b5c3deb28229/src/main/java/drmdgg/marijuanacraft/network/PacketButtonClicked.java#L28-L29
  • Topics

    • matt1999rd
      9
      [1.14-newer] deprecated method onBlockActivated

      By matt1999rd
      Started November 1

    • DragonITA
      1
      [1.14.4] Why minecraft with mod dont want start?

      By DragonITA
      Started 1 hour ago

    • plugsmustard
      43
      on/off button for custom furnace

      By plugsmustard
      Started Wednesday at 03:11 PM

    • JetCobblestone
      0
      [1.14] moving item assignment to a separate function

      By JetCobblestone
      Started 6 minutes ago

    • FaxeeK
      0
      Can't launch the game with forge

      By FaxeeK
      Started 43 minutes ago

  • Who's Online (See full list)

    • Lea9ue
    • matt1999rd
    • LexManos
    • FaxeeK
    • Vorquel
    • plugsmustard
    • DragonITA
    • xVoidZx
    • Silverpool64
    • Hendoor64
    • JetCobblestone
    • Atila1091
    • maycool12
    • vaartis
    • Draco18s
    • loordgek
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.7.10] Projectile stops in mid-air?
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community