1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| public Entity rayTrace()
{
if(entity instanceof EntityPlayer)
{
Vector3f cam = ((EntityPlayer)this.entity).getCameraPos();
float distanceZ = (float)(Math.cos(Math.toRadians(this.entity.getRotY())) * 0.3f);
float distanceX = (float)(Math.sin(Math.toRadians(this.entity.getRotY())) * 0.3f);
Vector3f playerDirection = new Vector3f(cam.x + distanceX, cam.y, cam.z + distanceZ);
Vector3f playerView = MathHelper.coordinate(cam, playerDirection);
for(Entity entity : Entity.entityList)
{
for(int k = 0; !entity.hitBox.collideWithVector(playerView); k++)
{
playerView = MathHelper.coordinate(cam.translate(k, 0, k), playerDirection.translate(k, 0, k));
if(entity.hitBox.collideWithVector(playerView))
{
System.out.println(entity);
return entity;
}
if(k>10)
break;
}
}
}
return null;
}
public boolean collideWithVector(Vector3f vec)
{
return(vec.x > this.minX && vec.x < this.maxX && vec.y > this.minY && vec.y < this.maxY && vec.z > this.minZ && vec.z < this.maxX);
} |
Partager