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.
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 ();
}
}
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;
}
}