Unreal Script - Aiming
So, it’s been nearly a week since I did anything productive in the UDK, mainly due to the great Steam Treasure Hunt, so I thought that tonight would be a good time to get back into it. Leaving off from last time, I had a semi-effective aiming system that would leave a player zoomed in, but not looking down the sights of the weapon.
Here’s a quick look at it in action:
As with the other videos, I have not yet developed any decent models or textures, but they will come in time – probably when I have an “art department” to do them for me.
For the curious ones among you, this is how I did it – taken directly out of my ZombiesWeapon.uc file:
//-----------------------//
// HUD DRAWING FUNCTIONS //
//-----------------------//
simulated function DrawWeaponXhair(ZombiesHUD HUD)
{
local vector2d CrosshairSize;
local float x, y, ScreenX, ScreenY, ScaleX, ScaleY, StartX,
OldOrgX, OldOrgY, OldClipX, OldClipY;
local ZombiesHUD H;
H = HUD;
if(H != none)
{
if( !(bZoomedIn))
{
//We're firing from the hip, as inaccurate as that is...
CrosshairSize.Y = CrosshairCoordinates.VL * H.Canvas.ClipY/720;
CrosshairSize.X = CrosshairSize.Y * CrosshairCoordinates.UL / CrosshairCoordinates.VL;
ChangeVisibility(true);
x = H.Canvas.ClipX * 0.5;
y = H.Canvas.ClipY * 0.5;
ScreenX = x - (CrosshairSize.X * 0.5);
ScreenY = y - (CrosshairSize.Y * 0.5);
if(CrosshairImage != none)
{
//Draw the crosshair
H.Canvas.SetDrawColor(255,255,255,200);
H.Canvas.SetPos(ScreenX, ScreenY);
H.Canvas.DrawTile(CrosshairImage, CrosshairSize.X, CrosshairSize.Y,
CrosshairCoordinates.U, CrosshairCoordinates.V,
CrosshairCoordinates.UL, CrosshairCoordinates.VL);
}
}
else
{
//We are zoomed in. Are we looking down the sights, or is it a sniper
if(bIsScoped)
{
//We're holding a sniper rifle, and can see some distance
//We need to make the rifle invisible in this view,
//as opposed to aiming down the sights...
ChangeVisibility(false);
// the sniper overlay is a special case that we want to ignore the safe region
OldOrgX = H.Canvas.OrgX;
OldOrgY = H.Canvas.OrgY;
OldClipX = H.Canvas.ClipX;
OldClipY = H.Canvas.ClipY;
H.Canvas.OrgX = 0.0;
H.Canvas.OrgY = 0.0;
H.Canvas.ClipX = H.Canvas.SizeX;
H.Canvas.ClipY = H.Canvas.SizeY;
bDisplayCrosshair = false;
ScaleY = H.Canvas.ClipY/768.0;
ScaleX = ScaleY;
StartX = 0.5*H.Canvas.ClipX - 512.0*ScaleX;
if ( (Instigator == None) || (Instigator.PlayerReplicationInfo == None)
|| (Instigator.PlayerReplicationInfo.Team == None)
|| (Instigator.PlayerReplicationInfo.Team.TeamIndex == 0) )
{
H.Canvas.SetDrawColor(48,255,0);
}
else
{
H.Canvas.SetDrawColor(64,64,255);
}
// Draw the crosshair
// Draw the 4 corners
H.Canvas.SetPos(StartX, 0.0);
H.Canvas.DrawTile(HudMaterial, 512.0 * ScaleX, 384.0 * ScaleY, 2, 0, 510, 383);
H.Canvas.SetPos(H.Canvas.ClipX*0.5, 0.0);
H.Canvas.DrawTile(HudMaterial, 512.0 * ScaleX, 384.0 * ScaleY, 510, 0, -510, 383);
H.Canvas.SetPos(StartX, H.Canvas.ClipY*0.5);
H.Canvas.DrawTile(HudMaterial, 512.0 * ScaleX, 384.0 * ScaleY, 2, 383, 510, -383);
H.Canvas.SetPos(H.Canvas.ClipX*0.5, H.Canvas.ClipY*0.5);
H.Canvas.DrawTile(HudMaterial, 512.0 * ScaleX, 384.0 * ScaleY, 510, 383, -510, -383);
if ( StartX > 0 )
{
// Draw the Horizontal Borders
H.Canvas.SetPos(0.0, 0.0);
H.Canvas.DrawTile(HudMaterial, StartX, 384.0 * ScaleY, 1, 0, 3, 383);
H.Canvas.SetPos(H.Canvas.ClipX - StartX, 0.0);
H.Canvas.DrawTile(HudMaterial, StartX, 384.0 * ScaleY, 4, 0, -3, 383);
H.Canvas.SetPos(0.0, H.Canvas.ClipY*0.5);
H.Canvas.DrawTile(HudMaterial, StartX, 384.0 * ScaleY, 1, 383, 3, -383);
H.Canvas.SetPos(H.Canvas.ClipX - StartX, H.Canvas.ClipY*0.5);
H.Canvas.DrawTile(HudMaterial, StartX, 384.0 * ScaleY, 4, 383, -3, -383);
}
// restore the canvas parameters
H.Canvas.OrgX = OldOrgX;
H.Canvas.OrgY = OldOrgY;
H.Canvas.ClipX = OldClipX;
H.Canvas.ClipY = OldClipY;
}
else
{
//We're looking down the sights (maybe with a red-dot or an ACOG)
H.Canvas.SetDrawColor(255,0,0,200);
H.Canvas.SetPos(ScreenX, ScreenY);
H.Canvas.DrawTile(CrosshairImage, CrosshairSize.X, CrosshairSize.Y,
CrosshairCoordinates.U, CrosshairCoordinates.V,
CrosshairCoordinates.UL, CrosshairCoordinates.VL);
//Wonder if we can just move the model here?
PlayWeaponAnimation('Aim-Idle', 10000);
}
}
}
}
1 comentários:
Queria saber como colocar esses scripts, alguém?
18 de fevereiro de 2011 às 17:39Postar um comentário
Seu comentário é importante para a manutenção do BLOG.
Não será publicado comentários que infringirem as seguintes regras:
01- ofensas gratuitas aos membros da UDKBrasil
02- descrédito para com a postagem
03- links com malwares ou qualquer tipo de fraude
04- palavras de baixo calão contra participantes
05- links de download não serão permitidos, a não ser que sejam gratuitos (freeware ou software de teste) e relacionados a UDK ou Computação Grafica.
Pedimos a gentileza de não USAR CAPS LOCK ligado.
OBS; assim que seu comentário for publicado,se junto dele NÃO houver uma resposta para sua dúvida,é porque não sabemos te responder...infelizmente, não sabemos de tudo!!
Seja bem vindo.