How to find a good point on an IAnimatedMesh to shoot at

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

How to find a good point on an IAnimatedMesh to shoot at

Post by JP »

Currently when one of my agents shoots at another agent they simply shoot at the centre of the enemy agent's bounding box. Unfortunatly on some of my agents this point is not actually within the Mesh, so the shot misses all the time.

So how can i get a good point on the mesh to shoot at? Basically want some point that's about in the centre of the mesh, and it would be good if there was some general way to find this so i didn't have to define a different point for each agent.
Image Image Image
dhenton9000
Posts: 395
Joined: Fri Apr 08, 2005 8:46 pm

Post by dhenton9000 »

Maybe the average point of all vertices? Sum all the xcomponents, divide by the number of vertices, and so for y and z?

HTH
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

That could work i guess...

But i'm not sure if i i can do that in the java-binding i'm using..

Would i just called node.getDefaultVertices()?

That doesn't actually seem like it would work...
Image Image Image
pfo
Posts: 370
Joined: Mon Aug 29, 2005 10:54 pm
Location: http://web.utk.edu/~pfox1

Post by pfo »

could you get the bounding box of the mesh and aim for the center of that?
Saku
Posts: 158
Joined: Wed Jan 05, 2005 8:48 am
Location: Denmark

Post by Saku »

How about making the shot more realistic by doing some random twisting of the path taken. This way you can simply add a little jitter to you original bullet.
Call me Wice, Miami Wice!
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Re: How to find a good point on an IAnimatedMesh to shoot at

Post by JP »

pfo:
JP wrote:Currently when one of my agents shoots at another agent they simply shoot at the centre of the enemy agent's bounding box.
saku: i really don't want to make the path of the projectile more complicated, just want to have a target on the enemy so that if it's shot at that point and the enemy doesn't move it will hit, cos otherwise it's making it impossible to hit one of the enemies when it's facing side on.
Image Image Image
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

you could always remember which vertex number is the 'heart' of your enemy and always aim a set distance behind it, or use a bone for the heart's position, or like Saku said make each bullet aim with a random offset. another idea, (which you probably wont like) who says the bullet needs to actually hit the mesh? im intersecting a line with a sphere for my bullet collision because its faster
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

How do i know which vertex number is the heart? I don't know how to access any of the vertices.. if i could then dhenton's suggestion would probably work...
Image Image Image
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Is it possible to grab a random triangle from the enemies triangle selector and then get a location vector from that?
Image Image Image
dhenton9000
Posts: 395
Joined: Fri Apr 08, 2005 8:46 pm

Post by dhenton9000 »

JP wrote:That could work i guess...

But i'm not sure if i i can do that in the java-binding i'm using..

Would i just called node.getDefaultVertices()?

That doesn't actually seem like it would work...

Meshbuffer getVertices() , I'm thinking....
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I've looked through the API and it seems you can only use a MeshBuffer with an IMesh, buti'm using an IAnimatedMesh, so how can i get the MeshBuffer for it?
Image Image Image
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Code: Select all

  s32 frame = AnimatedMeshSceneNode->getFrameNr();
  IMesh* mesh = AnimatedMesh->getMesh(frame, detail, start, end);

  s32 m, n = mesh->getMeshbufferCount();
  for(m = 0; m < n; ++m)
  {
    IMeshBuffer* buffer = getMeshBuffer(m);
    // do your business
  }
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Cheers! I'll give that a whirl later!
Image Image Image
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Well that worked, but not for the shooting..... as summing up and taking the average of the vertices points doesn't necessarily give a point within the mesh... In one example it gave a point between the agents outstretched arms, and so whent he agent was side on the shot didnt hit the agent...

any other suggestions? :s
Image Image Image
Guest

Post by Guest »

the best solution would be to place joints with your model tool, then you simply read out the joint position (in my game we have 3 joints, head, body and feat)
Post Reply