注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Mississippi的博客

学习使人进步

 
 
 

日志

 
 

UDK:简单的自动瞄准炮台  

2013-01-30 16:35:53|  分类: UnrealScript |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

一、资源

UDK:简单的自动瞄准炮台 - mississi - Mississippi的博客

BoneRotationSpace=BCS_ActorSpace

BoneRotation:Pitch=90,Yaw=90,Roll=0。

 

二、代码

class AutoTurret extends Pawn placeable;

 

var() SkeletalMeshComponent turretMesh;

var() class<Projectile> ProjClass;

 

var UTPawn EnemyTarget;

var SkelControlSingleBone Controller;

var Rotator InitRotation, SocketRotation, StartRotation, TargetRotation;

var Vector SocketLocation;

var float Delta, InterpTime;

 

function PostBeginPlay()

{

         super.PostBeginPlay();

         Controller = SkelControlSingleBone(turretMesh.FindSkelControl('PivotController'));

         InitRotation = Controller.BoneRotation;

         SetPhysics(PHYS_None);

         SetTimer(1.0,true);

}

function Timer()

{

         local Vector dir;

         GetPlayer();

         GetSocket();

        

         if(EnemyTarget != None)

         {

                   dir = ((EnemyTarget.Location  - SocketLocation)<<Rotation);

                   StartRotation = Controller.BoneRotation;

                   TargetRotation = RTransform(InitRotation, Rotator(dir));

                   SetControllerRotation();  

                   if(!IsTimerActive('BeginFire'))

                            SetTimer(1.0,false,'BeginFire');

         }      

}

 

function SetControllerRotation()

{

         InterpTime = 0;

         SetTimer(Delta,true,'RotateTimer');

}

 

function RotateTimer()

{

         InterpTime += Delta;

         if(InterpTime <= 1.0)

                   Controller.BoneRotation = RLerp(StartRotation,TargetRotation,InterpTime,true);

         else

                   ClearTimer('RotateTimer');

}

function BeginFire()

{

         if(FastTrace(EnemyTarget.Location,SocketLocation))

                   SetTimer(0.2,false,'TimedFire');

}

function TimedFire()

{

         local Projectile Proj;

         GetSocket();

         Proj =Spawn(ProjClass,self,,SocketLocation,SocketRotation,,True);

         Proj.Init(Vector(SocketRotation));

}

function GetPlayer()

{

         local UTPawn P;

         EnemyTarget = None;

         foreach WorldInfo.AllPawns(class'UTGame.UTPawn',P)

         {

                   if(P.Health > 0)

                   {

                            EnemyTarget = P;

                            break;                         

                   }

         }

}

 

function GetSocket()

{

         turretMesh.GetSocketWorldLocationAndRotation('FireLocation',SocketLocation,SocketRotation);

}

 

defaultproperties

{

         Begin Object Class=DynamicLightEnvironmentComponent Name=MyLightEnvironment0

         End Object

         LightEnvironment=MyLightEnvironment0

         Components.Add(MyLightEnvironment0)

         Begin Object class=SkeletalMeshComponent Name=SkeletalMeshComponent0

                   SkeletalMesh=SkeletalMesh'aaa.TurretMesh'

                   AnimTreeTemplate=AnimTree'aaa.TurretSkeletalMeshTree'

                   PhysicsAsset=PhysicsAsset'aaa.TurretMeshPhysics'

                   LightEnvironment=MyLightEnvironment0

         End Object

         turretMesh=SkeletalMeshComponent0

         components.Add(SkeletalMeshComponent0) 

         ProjClass=class'UTGame.UTProj_LinkPowerPlasma'

         Delta=0.033;  

}

 三、效果

UDK:简单的自动瞄准炮台 - mississi - Mississippi的博客
 
 
 
UDK:简单的自动瞄准炮台 - mississi - Mississippi的博客
 
UDK:简单的自动瞄准炮台 - mississi - Mississippi的博客
 

 

 

  评论这张
 
阅读(1023)| 评论(2)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017