Posted November 3, 201311 yr Hello guys, I've just made a new mob and I'd like to check if there's any other mob in front of it. If NOT my mob should throw an arrow, otherwise it shouldn't do that (so it shouldn't damage its "allies"). I'm actually creating an invisible entity for this which collides with any possible mob and check if my mob can shoot, but it wastes a lot of useful memory and packets. Is there any other way for doing that? Like for ex. a ray tracing way (I don't know what should I look for in order to learn about ray tracing)? Thanks and have a good day/night, Axel
November 4, 201311 yr Hi I'd suggest: (1) search for entities nearby. Discard any which are not nearby. (2) For each nearby entity, check whether its bounding box is intersected by the line of fire of the arrow (i.e. the bounding box has four vertical edges: if they are all to the left of your line of fire, or all to the right, then the arrow will miss. Otherwise it may hit. (3) optional: ray trace from the target entity to your mob, to see if there are any blocks in the way which would shield the entity from the arrow. I probably wouldn't bother with the ray trace myself, I suspect that in most cases it wouldn't actually make any difference and it's likely to be rather expensive to compute. Figuring out "left or right" requires a bit of vector math, not too hard if you've studied math, but let us know if you need a pointer in the right direction. Alternatively - you could just make your mob immune to its own arrows. Would be an awful lot easier. -TGG
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.