[SOLVED] Proper method to force a mob to look at a given location?

Started by Lofty on

Topic category: Help with modding (Java Edition)

Last seen on 04:04, 3. Feb 2023
Joined Dec 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[SOLVED] Proper method to force a mob to look at a given location?
Thu, 12/22/2022 - 19:07 (edited)

Hi friends,

What is the correct way to tell a mob to point at a particular location?

Custom code examples or procedure examples would both be helpful!


Here is what I am trying to rotate:
1. Make new LivingEntity
2. Behavior -> Is flying entity
3. Enable AI (empty)

I want to make the entity look at a specific point as it moves.


These phantoms are intended to: 
Spawn above the block (working)
Circle down toward the block (movement working, rotation not working) 
Touch the block (working)
Then circle back up into the sky and despawn (movement working, rotation not working)


Here are some things I have tried, but were not successful:

Procedure image

Some custom code I tried - not successful:

@Override
	public void baseTick() 
	{
		super.baseTick();
		
		
//this sets NBT for velX, velY, and velZ
		PhantomailCourierTickSpicyProcedure.execute(this);

		double velX = getPersistentData().getDouble("velX");
		double velY = getPersistentData().getDouble("velY");
		double velZ = getPersistentData().getDouble("velZ");

		//DOES NOT WORK IN THIS EXAMPLE
		//use look controller to point the mob at a position
		lookControl.setLookAt(position().x + velX, position().y + velY, position().z + velZ);
		lookControl.tick();

		//DOES NOT WORK IN THIS EXAMPLE
		//attempt to set yaw to face the direction we are moving in - multiply by radians to degrees
		setRot((float)(Math.atan2(velZ,velX) * 57.2958),(float)0);
		
		
//Not sure what these do - doesn't appear to do anything

		setXxa((float)90);		
		

setZza((float)-90);

	}

Here is a copy of the procedure if that helps:

https://cdn.discordapp.com/attachments/1054132569886703717/105517741479…

Edited by Lofty on Thu, 12/22/2022 - 19:07
Last seen on 04:04, 3. Feb 2023
Joined Dec 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
After a bunch of trial-and…
Thu, 12/22/2022 - 19:07

After a bunch of trial-and-error, I figured out what I wanted.

There were 3 required things:

setDeltaMovement
moveControl.setWantedPosition
lookControl.setLookAt

As far as I can tell, these had to be done in that specific order.