Jump to content

Need to know the meaning of the function "getInputVector"


Vat1n

Recommended Posts

Hello.

I was searching the signification of the method getInputVector(). I've found it in Entity.java

private static Vec3 getInputVector(Vec3 pRelative, float pMotionScaler, float pFacing) { 
double d0 = pRelative.lengthSqr(); 
if (d0 < 1.0E-7D) { 
	return Vec3.ZERO;
} else { 
	Vec3 vec3 = (d0 > 1.0D ? pRelative.normalize() : pRelative).scale((double)pMotionScaler); 
	float f = Mth.sin(pFacing * ((float)Math.PI / 180F)); 
	float f1 = Mth.cos(pFacing * ((float)Math.PI / 180F));
	return new Vec3(vec3.x * (double)f1 - vec3.z * (double)f, vec3.y, vec3.z * (double)f1 + vec3.x * (double)f); 
  } 
}

Here is another function which uses the getInputVector :

public void moveRelative(float pAmount, Vec3 pRelative) {
      Vec3 vec3 = getInputVector(pRelative, pAmount, this.getYRot());
      this.setDeltaMovement(this.getDeltaMovement().add(vec3));
   }

Could someone explain me what is the goal of this method please ?

Link to comment
Share on other sites

Thank you for your answer. I understand now : Imagine you want to move diagonally (in relation to the axes X and Z), you have to set X movement and Z movement. Then we'll have to deal with Pythagorean theorem or something like that in order to get the correct value for the diagonal movement 😄

Edited by Vat1n
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.



×
×
  • Create New...

Important Information

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