Jump to content

Recommended Posts

Posted (edited)

So I'm creating a mod that adds a bunch of new tool- and weapon types. One of them should make the player dash forward when they charged it.

I was able to use some of the bow's code to make the charging work but neither do I know how to get the Horizontal Direction that the player's facing as a 3dVector, nor do I know how to accelerate a LivingEntity in a given direction. 

So how can I make a player dash in the horizontal direction they're facing? 

Edited by FenrisFox86
  • FenrisFox86 changed the title to [1.16.4] Make LivingEntity move in the Direction it's facing
Posted
1 hour ago, FenrisFox86 said:

I was able to use some of the bow's code to make the charging work but neither do I know how to get the Horizontal Direction that the player's facing as a 3dVector, nor do I know how to accelerate a LivingEntity in a given direction.

you can get it via Entity#getViewVector, use as the float parameter 1 else the value will be lerp with the current view vector, the last view vector and the parameter you given

 

1 hour ago, FenrisFox86 said:

So how can I make a player dash in the horizontal direction they're facing?

not sure but try to scale the vector

Posted (edited)

Solved: 

I made the stupid mistake to handle movement server-side first. That's why the movement never worked. The method Entity#getLookVector returns the correct vector and I simply had to pass it to the Entity#setMotion method. 

Edited by FenrisFox86
Posted

Just something important for people trying to do a similar thing: normalize the vector and then multiply it by a factor you need. Otherways the vector's going to be as long as the player's distance to the block they're facing so the dash won't have a consistent length. 

Vector3d vector = player.getLookVec().normalize().mul(factor, factor, factor);
player.setMotion(vector);

 

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.