About Store Forum Documentation Contact
Donations:
345$/mo



Post Reply 
Help with character to ms.pos inaccurancy
Author Message
SamNainocard Offline
Member

Post: #1
Help with character to ms.pos inaccurancy
Hi,
currently I have try to implementing the mouse aim which turn a character to mouse position and shoot at it in TPP. Think about tank turret.
Right now it's very inaccuracy.

[Image: oo271.jpg]

And this is my code using in Bloody Massacre.
Code:
static void DrawCrosshair()
{
   if(View!=VIEW_ISO)
   {
       MouseVisibility();
       Flt step=0.0000001f, time=Time.d()*2.75;
       Vec2 mspos=Ms.pos();
       if (mouseAim.getbtn() && !centerAim.getbtn() && InvGui.window.hidden() && !Kb.b(KB_Z))
       {
                    mspos=Ms.pos();
       }else mspos=0;
        mspos=Vec2(mspos_x, mspos_y);
        VI.line(Color(255,255,255,32),Color(255,255,255,80), mspos+Vec2(-0.04f, 0.00f),mspos+Vec2(-0.004f, 0.00f));
        VI.line(Color(255,255,255,32),Color(255,255,255,80), mspos+Vec2( 0.04f, 0.00f),mspos+Vec2( 0.004f, 0.00f));
        VI.line(Color(255,255,255,32),Color(255,255,255,80), mspos+Vec2( 0.00f,-0.04f),mspos+Vec2( 0.00f,-0.004f));
        VI.line(Color(255,255,255,32),Color(255,255,255,80), mspos+Vec2( 0.00f, 0.04f),mspos+Vec2( 0.00f, 0.004f));
        VI.end ();
   }
}

And Player::shoot
Code:
void Player::shoot(Bool left)
{
   Reference<Item> &weapon=inv.slot[left ? SLOT_ARM_L : SLOT_ARM_R];

   if(weapon.valid())
      if(weapon().type==ITEM_WEAPON)
         switch(weapon().type2)
   {
      case WEAPON_RIFLE :
      case WEAPON_PISTOL:
      {
         Bullet &bullet=Bullets.New();

         C Vec  &dir   =Cam.matrix.z;
                    Vec     pos   =weapon().pos()+dir*0.2f;
         if (mouseAim.getbtn() && !centerAim.getbtn() && !Kb.b(KB_Z)) ScreenToPosDir(Ms.pos(),Cam.matrix.pos,Cam.matrix.z);

         // if weapon has a skeleton then choose a more appropriate shooting position
         if(weapon().skeleton)
            if(SkelPoint *point=weapon().skeleton->findPoint("shot"))
               pos=point->pos*weapon().matrixScaled();
         bullet.set(pos, dir, this);
      }break;
   }
}

I doubt it's math problem (which I'm not good at).
(This post was last modified: 07-20-2011 10:00 AM by SamNainocard.)
07-20-2011 09:47 AM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #2
RE: Help with character to ms.pos inaccurancy
Couple things I would try:

Code:
if(SkelPoint *point=weapon().skeleton->findPoint("shot"))
{
    pos=point->pos*weapon().matrixScaled();
    dir=point->dir*weapon().matrix();
}

and/or:

Code:
if (mouseAim.getbtn() && !centerAim.getbtn() && !Kb.b(KB_Z))
    ScreenToPosDir(Ms.pos(), pos, dir);

Both are in player::shoot().
07-20-2011 06:48 PM
Find all posts by this user Quote this message in a reply
SamNainocard Offline
Member

Post: #3
RE: Help with character to ms.pos inaccurancy
Thanks for the reply, but
putting dir=point->dir*weapon().matrix(); and it seems to shoot to nowhere.
[Image: o4vz2.jpg]

ScreenToPosDir(Ms.pos(), pos, dir); seems to same with ScreenToPosDir(Ms.pos(),Cam.matrix.pos,Cam.matrix.z);

Putting ScreenToPosDir(Ms.pos(), pos, dir); before bullet.set(pos, dir, this);
will shoot the bullets from crosshair instead.

[Image: vbmk3.jpg]

I currently download X3 Reunion demo (not sure if reunion have mouse aim) to see if it that accuracy.
07-21-2011 05:56 AM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #4
RE: Help with character to ms.pos inaccurancy
Maybe just:

Code:
dir = point->dir;

Or:

Code:
dir = !(point->dir * weapon().matrix() - pos);
07-21-2011 08:27 AM
Find all posts by this user Quote this message in a reply
SamNainocard Offline
Member

Post: #5
RE: Help with character to ms.pos inaccurancy
Hmm, it's still shoot at nowhere.
07-22-2011 05:41 AM
Find all posts by this user Quote this message in a reply
Post Reply