Jump to content

[1.12.2] Making player move/float towards certain destination


Naomiora

Recommended Posts

Basically what the title says, cancelling WASD and Spacebar keys. Then make the player float/move towards a certain destination. I got it to work for entities such as a cow or skeleton etc. the code I currently use to move an entity towards a location (in this case the location is another entity) is this:

 

	public void pullEntityToEntity(Entity entity, Entity secondEntity, double moveFactor) {
		double distX = entity.posX - secondEntity.posX;
		double distZ = entity.posZ - secondEntity.posZ;
		double dir = MathHelper.atan2(distZ, distX);
		double speed = 1f / secondEntity.getDistance(entity.posX, entity.posY, entity.posZ) * moveFactor;

		secondEntity.motionX = MathHelper.cos((float) dir) * speed;
		secondEntity.motionZ = MathHelper.sin((float) dir) * speed;
	}

 

 

the code I use to freeze certain entities is:

 

	public void freezeEntity(Entity entity) {
		entity.setVelocity(0, 0, 0);
		if (entity.prevPosX != entity.posX || entity.prevPosY != entity.posY || entity.prevPosZ != entity.posZ) {
			entity.posX = entity.prevPosX;
			entity.posY = entity.prevPosY;
			entity.posZ = entity.prevPosZ;
		}
    }

 

 

I also tried a simple network message to disable the WASD and spacebar key, which eventually turned out not to work.

 

I googled around why I couldn't change the entityplayer's position + velocity but I could not find why. The code above does work for other entities that isn't a EntityPlayer.

 

 

Thanks for reading and possibly your help! ^^

Link to comment
Share on other sites

	@SubscribeEvent
	public static void inputListener(InputUpdateEvent event) {
		if(ClientModule.isFrozen) {
			event.getMovementInput().moveStrafe = 0;
			event.getMovementInput().backKeyDown = false;
			event.getMovementInput().forwardKeyDown = false;
			event.getMovementInput().jump = false;
			event.getMovementInput().leftKeyDown = false;
			event.getMovementInput().rightKeyDown = false;
		}
	}

 

 

It does freeze most of my movement keys, except for my forwardkey and backkey. why do exactly those 2 keys still work?

Link to comment
Share on other sites

22 minutes ago, diesieben07 said:

Maybe you should set MovementInput#moveForward to 0 as well.

Oh, I didn't see that one! Ill look better next time! Thank you! Now the freezing part is solved, but how do I make the player float/move towards the certain location though? The code I currently have only works on Living AI-entities. Do I do that part in the InputUpdateEvent? I don't think so, if so thats gonna be alot of hard work xD

Edited by Naomiora
Link to comment
Share on other sites

48 minutes ago, diesieben07 said:

You'll have to adjust the position every tick. There is no "automatic movement" for players.

So something like this:
 

	public void pullEntityToEntity(Entity entity, Entity secondEntity, double moveFactor) {
		double distX = entity.posX - secondEntity.posX;
		double distZ = entity.posZ - secondEntity.posZ;
		double dir = MathHelper.atan2(distZ, distX);
		double speed = 1f / secondEntity.getDistance(entity.posX, entity.posY, entity.posZ) * moveFactor;

		secondEntity.motionX = MathHelper.cos((float) dir) * speed;
		secondEntity.motionZ = MathHelper.sin((float) dir) * speed;
	}

 

shouldn't work for an EntityPlayer? (secondEntity is the EntityPlayer in this case) If you think it should work, it doesn't for me. All it does is nothing, it does get casted though.

Link to comment
Share on other sites

You can use linear interpolation to smoothly move between two points. You will need the original start position, the final destination position and the amount between them the player should be. 

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

  • 2 weeks later...
On 3/25/2019 at 4:24 AM, Cadiboo said:

You can use linear interpolation to smoothly move between two points. You will need the original start position, the final destination position and the amount between them the player should be. 

Sorry for the horribly late reply, I tried doing this but I already knew maths wasn't my strongest part in life. I couldn't get it to work, and eventually recoded parts of my mod because I thought the reason why it didn't work was because of some other parts affecting the entities movement etc etc. So sorry for asking more help into the linear interpolation part, but could you explain how that'd work?

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
  • Topics

×
×
  • Create New...

Important Information

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