Jump to content

Launching in direction looking?


GravityWolf

Recommended Posts

I am fairly new to making mods, and I am making an item that launches you up and sends you launching in the direction you are looking. Here is the code I am currently using to make the player launch up when they right click with the item:

 

@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {

	player.motionY = 0.7;
	return itemStack;

}

 

Any ideas? Thanks!

Link to comment
Share on other sites

my teleport spell uses thsi

 

 

double motionX = 20 * (double) (-MathHelper.sin(player.rotationYaw/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * f);
	double motionZ = 20 * (double) (MathHelper.cos(player.rotationYaw	/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * f);
	double motionY = 20 * (double) (-MathHelper.sin((player.rotationPitch)/ 180.0F * (float) Math.PI) * f);

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

my teleport spell uses thsi

 

 

double motionX = 20 * (double) (-MathHelper.sin(player.rotationYaw/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * f);
	double motionZ = 20 * (double) (MathHelper.cos(player.rotationYaw	/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * f);
	double motionY = 20 * (double) (-MathHelper.sin((player.rotationPitch)/ 180.0F * (float) Math.PI) * f);

 

On "* f" It gives me an error, are you using a variable that you had or something? It crashes when I use the item.

Link to comment
Share on other sites

lolol, yes, its technily 0.4f but you could tottally remove it and it wouldnt change anything

 

Hmm..I put it in my onItemRightclick method and it does nothing...here is this code:

 

@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {

	player.motionY = 0.7;
	double motionX = 20 * (double) (-MathHelper.sin(player.rotationYaw/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * 0.4f);
	double motionZ = 20 * (double) (MathHelper.cos(player.rotationYaw	/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * 0.4f);
	double motionY = 20 * (double) (-MathHelper.sin((player.rotationPitch)/ 180.0F * (float) Math.PI) * 0.4f);

	return itemStack;

}

 

Sorry about my noobishness, I am new to modding like I said  :P

 

Edit: Is Pi already in Eclipse/Forge/Minecraft, or is it another class you have? Same with MathHelper.

Link to comment
Share on other sites

new to coding ?

 

ok lets take it step by step

 

double motionX = 20 * (double) (-MathHelper.sin(player.rotationYaw/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * 0.4f);
	double motionZ = 20 * (double) (MathHelper.cos(player.rotationYaw	/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * 0.4f);
	double motionY = 20 * (double) (-MathHelper.sin((player.rotationPitch)/ 180.0F * (float) Math.PI) * 0.4f);

 

so heres my code, basicly it will calculate the translation on all 3 different axis

 

double motionX = 3;
double motionY = 3;
double motionZ = 3;

 

so this code would technicly tell the program

"yo btw i have 3 variable, one called motionX and value of 3, one called motionY and value of 3 and a last one called motionZ and value of 3"

 

now this does NOTHIGN on its own because all it says is  "hey i have these values" it doesnt do anythign with them

 

now lets take a look at your line of code

player.motionY = 0.7;

basicly this is saying to the program

"btw buddy, can you take the "player" and take a look at its "motionY" value, and while you're there can you assign it the value of 0.7"

 

now im going to write one of the 3 lines requires to make this work and youll write the 2 other

 

public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {

	player.motionY = 0.7;
	double calculatedX= 20 * (double) (-MathHelper.sin(player.rotationYaw/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * 0.4f);
	double calculatedZ = 20 * (double) (MathHelper.cos(player.rotationYaw	/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * 0.4f);
	double calculatedY = 20 * (double) (-MathHelper.sin((player.rotationPitch)/ 180.0F * (float) Math.PI) * 0.4f);
	 player.motionY = calculatedY;
                 //another line of code for another axis
                 //another line of code for the last axis

	return itemStack;

}

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

to negate fall damage do this: (based on hydro's code)

 

public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {

 

 

double calculatedX= 20 * (double) (-MathHelper.sin(player.rotationYaw/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * 0.4f);

double calculatedZ = 20 * (double) (MathHelper.cos(player.rotationYaw / 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * 0.4f);

double calculatedY = 20 * (double) (-MathHelper.sin((player.rotationPitch)/ 180.0F * (float) Math.PI) * 0.4f);

 

          player.fallDamage = 0.0F;

               

          player.motionY = calculatedY;

                //another line of code for another axis

                //another line of code for the last axis

 

return itemStack;

 

}

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.