Jump to content

How to make my custom entity look at the player/other entities?


herar123

Recommended Posts

Hello,
I created a custom entity which shoots snowballs at the player and other mobs. Now I want it to look at the target while doing so --> rotating its head to it/at least rotate its body in the targets direction
I tried to use this.lookAt(enitity) which doesnt seem to work.

Spawning Particles doesnt work either :(

public void tick() {
			this.attackTimer++;
			LivingEntity targetentity = this.snowmanCannon.getTarget();
			this.snowmanCannon.setAttacking(true);
			Level level = this.snowmanCannon.level;
			this.snowmanCannon.getLookControl().setLookAt(targetentity);
			
			if(!this.snowmanCannon.hasLineOfSight(targetentity)) {
				
			} else if (this.attackTimer == 1) {
				this.snowmanCannon.setAttacking(true);
				Vec3 pos1 = this.snowmanCannon.getEyePosition().add(0,-0.5,0);
				Vec3 pos2 = targetentity.getEyePosition();
				Vec3 dir = pos2.subtract(this.snowmanCannon.getEyePosition());
				SnowmanCannonProjectile snowball = new SnowmanCannonProjectile(level, pos1.x, pos1.y, pos1.z);
			    snowball.shoot(dir.x, dir.y, dir.z, 4.5F, 0.1F);
			    this.snowmanCannon.playSound(SoundEvents.SNOW_GOLEM_SHOOT, 1.0F, 1.0F);
			    
			    level.addAlwaysVisibleParticle(ParticleTypes.EXPLOSION, pos1.x, pos1.y, pos1.z, 1d, 1d, 1d);
				
			    level.addFreshEntity(snowball);
			} if (this.attackTimer == 3) {
				this.snowmanCannon.setAttacking(false);
				this.attackTimer = 0;
			}
		} 

Thank you for any help

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



×
×
  • Create New...

Important Information

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