udoprog wrote:
Looks very cool : D.
Only two things; it feels like the horizontal forces should be dampened a bit while squishy is airborne or lifted by his arm.
Thanks for the comments. I do need to tweak the movement a bit.
udoprog wrote:
Also, the raytracer (?) behaves a bit weird when the sling is fired over an edge, it feels like it should stick on the other side but it pops up on the side squishy is facing.
It's not actually a raytrace - while the grapple is being fired, the blob on the end is actually a rigid circle. I listen for a contact with the map then destroy the body and create a distance joint from the contact position to the centre of squishy so it is a bit hard to change. The distance joint doesn't actually exist until the grapple locks - the line drawn between the blob and squishy is literally just that until it locks.
udoprog wrote:
I am also interested in how you solved where the mouse was clicking since I am looking for a nice solution for that in a game i'm currently working on.
Sure.
This is a D3D app being rendered with an ortho projection so I don't know if this will apply to your application, but given the previously computed view matrix View (based on squishy position and map extremities) and projection matrix Proj, the following fills in a D3DXVECTOR3 representing the mouse world position:
Code:
void ComputeMousePos()
{
POINT Pt; GetCursorPos(&Pt);
D3DVIEWPORT9 Vp;
Graphics.GetDevice()->GetViewport(&Vp);
MousePos.x=(((2.0f*float(Pt.x))/Vp.Width)-1.0f)/Proj(0,0);
MousePos.y=(((-2.0f*float(Pt.y))/Vp.Height)+1.0f)/Proj(1,1);
MousePos.z=0;
D3DXMATRIX ViewInv;
D3DXMatrixInverse(&ViewInv,0,&View);
D3DXVec3TransformCoord(&MousePos,&MousePos,&ViewInv);
}
I basically transform the screen pos back into view space based on the viewport and projection matrix, then transform the view space position back into world space by transforming by the inverse of the view matrix. It is based on some code in Frank Luna's 3D Game Programming with DirectX in the chapter on picking with rays.