Jump to content

Recommended Posts

Posted

I'm trying to make a staff kind of weapon. My plan is for it to cast lightning where ever the player is looking, but how would I get the block that the player is looking at?

Kain

Posted

You can try using 'getMovingObjectPositionFromPlayer' method to return a MovingObjectPosition, but that will only get you a tile if it is within reach distance. Otherwise, you will need to use vector's from the player's look position:

Vec3 vec3 = player.getPosition(1.0F);
Vec3 vec3a = player.getLook(1.0F);
Vec3 vec3b = vec3.addVector(vec3a.xCoord * distance, vec3a.yCoord * distance, vec3a.zCoord * distance);

MovingObjectPosition movingobjectposition = world.clip(vec3, vec3b);

There may be a better/simpler way than this, but this worked for my purposes. The MovingObjectPosition will contain information on the tile hit, if any. Be sure to null-check.

  • Guest locked this topic
Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

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