Change Projectile Gravity

Started by redreddyred on Wed, 06/27/2018 - 01:16

Topic category: Advanced modding

Last seen on 17:30, 2. Jul 2018
Joined Jun 2018
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Change Projectile Gravity
Wed, 06/27/2018 - 01:20 (edited)

I created a gun item in 1.7.9. and it works great! However, I would like the projectile to fire in a straight line, and not arch how an egg or a snowball would. I've locked the code so I can edit the java under code view. I'm trying to find the line of code that will allow me to manipulate the physics of the projectile. What do I need to add or change in order to accomplish a straight forward firing projectile for my new item?

Thanks for the assistance!

Edited by redreddyred on Wed, 06/27/2018 - 01:20
Last seen on 17:30, 2. Jul 2018
Joined Jun 2018
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Bump, anyone? I feel like…
Fri, 06/29/2018 - 18:53

Bump, anyone? I feel like this is something so easy to change but I can't figure out what to manipulate or add to accomplish this.

Last seen on 14:19, 15. Sep 2018
Joined May 2014
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
The only thing I can think…
Sat, 06/30/2018 - 21:28

The only thing I can think of is making a procedure for the gun and making the gun when right clicked when spawn an entity.  You could then apply some force to it when it is shot.  For making it go in a straight line that's a little bit different.  There is no block in the procedures for gravity but I have two ideas, one:  (probably not ideal) apply an upwards force to the entity opposite to the gravity or Idea two: look in the code editor for the entity and find the line for gravity and set that to false or 0 (not sure what it is called though).  Now you could just make it so once the bullet entity collides with another it'll apply some damage to the hit entity.  

That's my ideas on how you could achieve this.  you could probably do it another way.  I doubt this is the best way but hope this helped you out some.

Last seen on 17:30, 2. Jul 2018
Joined Jun 2018
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
I did mess around with the…
Sat, 06/30/2018 - 21:58

I did mess around with the current code. I made the force 0, which just drops the item complete when you shoot it. Then I tried -1 but that didn't do anything. I'll have to play around with the procedures. Maybe I can find something there that would offset the gravity.

I'm still hoping someone knows the line of code, and where to put it, to make this thing just fire without being affected by gravity. I feel like this should be something so easy to do. Hell the bedrock edition already has it in there (see below)

  "power": 1.6,
    "gravity": 0.00,
    "uncertaintyBase": 4,
    "uncertaintyMultiplier": 1,
    "anchor": 0,
    "offset": [ 0, -1, 0 ]

Obviously that's the the bedrock edition, but the gravity snippet you set to zero, and it works like a charm.

Last seen on 14:19, 15. Sep 2018
Joined May 2014
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
I tried looking the code for…
Sat, 06/30/2018 - 22:15

I tried looking the code for the ranged item but couldn't find anything like gravity that's obvious but I bet its there somewhere.

Last seen on 17:30, 2. Jul 2018
Joined Jun 2018
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
As far as I can tell, below…
Sun, 07/01/2018 - 03:36

As far as I can tell, below is the chunk of code that manipulates the force/physics of the item shoot. It's actually the chunk of code labeled, par3EntityPlayer.getLookVec().z, f * 2.0F, 0);

if (flag || par3EntityPlayer.inventory.hasItemStack(new ItemStack(Blocks.AIR))) {
				float f = 1.5F;
				EntityArrowCustom entityarrow = new EntityArrowCustom(par2World, par3EntityPlayer);
				entityarrow.shoot(par3EntityPlayer.getLookVec().x, par3EntityPlayer.getLookVec().y, par3EntityPlayer.getLookVec().z, f * 2.0F, 0);
				entityarrow.setIsCritical(false);
				entityarrow.setDamage(2.5);
				entityarrow.setKnockbackStrength(2);
				if (false) {
					entityarrow.setFire(100);

But every time I mess with that 2.0F I can never get it to work correctly. It will either just drop to the ground as soon as I fire, or still arch like a snowball or an egg. There has to be a simple change or addition can make to get this working...

Last seen on 17:30, 2. Jul 2018
Joined Jun 2018
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
I got it. Someone over on…
Sun, 07/01/2018 - 05:23

I got it. Someone over on Minecraft Forums helped me out. You add this line in, and it worked.

entityarrow.setNoGravity(true);

BINGO! Thanks for trying to help me out with this my dude.