Jump to content

RayTrace help


Tryhard

Recommended Posts

I'm trying to get the position of the block the player is aiming at:

 

private BlockRayTraceResult rayTrace(PlayerEntity playerIn, float reach) {
		
  Vector3d pos = playerIn.getPositionVec();
  Vector3d forward = playerIn.getLookVec();
  Vector3d rayVector = forward.scale(reach);

  return playerIn.world.rayTraceBlocks(pos, rayVector, ?, ?, ?);
}

I understand what the vectors are doing. My only 2 questions are simple:

 

1.- For the vector i call 'pos', should i be using player.getEyePosition instead?

                    if so, it's argument is a float called partialTicks, what does this argument represent?

2.- what are the three last arguments for world.rayTraceBlocks? 

                    i understand the first one is the start of the ray, and the second the end of it. But no clue about what the others are supposed to be

 

I've tried looking for info on this method and i found nothing.

Edited by Tryhard
Link to comment
Share on other sites

Nevermind, i figured it out. I simply wanted to get the position the player is aiming at, and summon lightning at that point, to do so i  needed to raytrace.

I solved my previous problem by using RayTracingContext. Code looks like this now.

image.thumb.png.49392ceca09486ad9cc440d6ea085e07.png

 

Then, from the method in which i spawn lightning:

 

image.thumb.png.6cd7036eb3c11ea6553289cf168bd010.png

 

This works as i want it, right now. Any advice from the pros on what could be done better?

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.