Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • Author

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

you can handle it on server-side just set after handling (Server)PlayerEntity#hurtMarked to true this will update the player and also the movement

  • Author

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.