Posted November 8, 201311 yr I'm trying to make a projectile that will home in on the nearest enemy, but have no idea where to start. Is there any function that can give coords of the nearest mob or something like that? I really don't know what to do, there isn't much documentation on this... Creator of Metroid Cubed! Power Suits, Beams, Hypermode and more! http://i.imgur.com/ghgWmA3.jpg[/img]
November 8, 201311 yr I guess you could try finding out how entities move and get the location of the entity you want to kill. There was something with AxisAllignedBB for detecting entities within the bounding box. Kain
November 8, 201311 yr Yep you can use an AABB, center it on the player and make it the size you want the range to be. Use an Iterate over all entities inside the AABB, keep track of the one closest to the player. Then fire projectile towards the target. There is no documentation on how to do this kind of thing, there is documentation for most of the methods you can use. Documentation doesn't tell you every scenario you can use something in, it just tells you how it's supposed to work and you will have to decide when and how to use it for your purposes. Welcome to programming, it's more about designing the logic than it's about typing the code. If you guys dont get it.. then well ya.. try harder...
November 8, 201311 yr Author I meant I couldn't find anything about finding the nearest entity, but thanks for the idea about the AABB, i'll try it out! Creator of Metroid Cubed! Power Suits, Beams, Hypermode and more! http://i.imgur.com/ghgWmA3.jpg[/img]
November 8, 201311 yr Yeah as I said there is NO method made for doing that specifically but some things such as the AABB could be used to accomplish this goal. There are probably several other ways, but the best way that I currently know of is to use the bounding box for it Good luck! If you guys dont get it.. then well ya.. try harder...
November 8, 201311 yr Hi You could look in EntityAINearestAttackableTarget for inspiration. It does pretty much exactly what Mazetar described. and for homing it EntityAIMoveTowardsTarget -TGG
November 8, 201311 yr Author Hmm ok I got the AABB set up but am not sure what to do with it, IE how to redirect my projectile towards said entity. I don't see a way to get the coords of the entity either, did I do it right? This is what I did: AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(this.posX - 16, this.posY, this.posZ - 16, this.posX + 16, this.posY + 16, this.posZ + 16); public void getNearestEntity(){ List<IMob> entities = worldObj.getEntitiesWithinAABB(IMob.class, bb); Iterator iter = entities.iterator(); while(iter.hasNext()){ if(iter.next() instanceof IMob){ IMob ent = (IMob)iter.next(); //What do I do from here? } } } Sorry if it's really obvious and i'm just really stupid, i'm still not too experienced (IK java i'm just not used to working with it in this way) Creator of Metroid Cubed! Power Suits, Beams, Hypermode and more! http://i.imgur.com/ghgWmA3.jpg[/img]
November 16, 201311 yr Author I still haven't been able to get this to work, I don't know where to set up the AABB, or what to do with the entity selected Creator of Metroid Cubed! Power Suits, Beams, Hypermode and more! http://i.imgur.com/ghgWmA3.jpg[/img]
November 16, 201311 yr Hi So what you are basically trying to do is In your entity onUpdate: (1) create a bounding box centred around where the projectile currently is. (2) find all entities within that bounding box (3) loop through them all: (a) if this isn't a valid target, ignore it (b) calculate the distance from the target to the projectile. If it's less than the shortest distance found so far, this is now your closest target. (4) change motionX, motionY, motionZ to point to the closest target You can probably copy the onUpdate code from EntityThrowable and tweak it to add the code above. It looks like you've figured out (1) and (2) already, just need to code up the rest. It won't do anything fancy like check whether the missile can actually see the target (blocks in the way), but you could add that later if you really want, once the basics are working? -TGG PS It looks like this bloke is also doing something very similar to what you want, perhaps you should message him too... http://www.minecraftforge.net/forum/index.php/topic,13829.0.html
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.