Laser dot

All about Chaos for Unreal... (UT3, UT2004, UT2003, UT)
Post Reply
UndeadRoadkill
Posts: 5
Joined: Sun Jun 19, 2005 2:51 am

Laser dot

Post by UndeadRoadkill »

I'm not sure if this is the right forum to post under, but maybe one of you guys can help me. I've been trying to put the CUT sniper laser dot onto another weapon (for my own personal education and use, I wouldn't distribute it), and I can't seem to get it to behave properly. I've gotten it so when you pull the weapon out, a laser dot appears in front of your face and hovers in the air, without moving.

I thought I used all the right code from the sinper rifle, but I seem to be missing something. I can't really write code, I can just sort of 'interpret' some of it. Can anyone show me the code I need to get the dot to work right?
jb
Posts: 9825
Joined: Fri May 03, 2002 12:29 am
Location: Coral Springs, FL
Contact:

Post by jb »

Well we can help you learn...post what you have and we can see what you have missed....
Jb
UndeadRoadkill
Posts: 5
Joined: Sun Jun 19, 2005 2:51 am

Post by UndeadRoadkill »

Thanks. I know I have some extra things in that don't relate directly to the laser dot, but I put them in anyway to just to avoid compile errors, and looking back it seems I missed a reference to the laser dot in the renderoverlay part, but I don't know how to isolate just the part for the laser, and how to cut out the rest. Here is what I have right now:

class SGOMPX extends SGOMPS
placeable;

// added laser dot
var LaserDot LaserDot;
var bool bDotActive;
var float Distance; // Real-time dot distance
var bool bIRVision;
var bool bIsChanging;
var float TickTimer;
var bool bFlash;

replication
{
// Things the server should send to the client.
reliable if( Role==ROLE_Authority )
bDotActive, bIRVision;

reliable if (bNetOwner && Role==ROLE_Authority)
LaserDot;

// functions called by client on server
reliable if( bNetOwner && Role<ROLE_Authority )
ChangeDot, DownWeapon;//use this to properly remove the laser dot and prevent use

from using the AWO key when switching to another weapon
}

simulated function PostBeginPlay()
{
Super.PostBeginPlay();
FireMode[1].FireAnim = 'Idle';
}

simulated function Destroyed()
{
Super.Destroyed();
DestroyLaserDot();
if (Level.NetMode == NM_DedicatedServer)
return;
// restore xhairs
if (Instigator != None && Instigator.PlayerReplicationinfo != none &&

!Instigator.PlayerReplicationinfo.bBot &&
Instigator.Controller != none && PlayerController(Instigator.Controller).myHUD !=

None)
PlayerController(Instigator.Controller).myHUD.bCrosshairShow =

PlayerController(Instigator.Controller).myHUD.default.bCrosshairShow;
}

//function for destroying the laserdot
function DestroyLaserDot()
{
if (LaserDot != None)
{
LaserDot.Destroy();
LaserDot = None;
}
}

//set up laserdot appropriately, to on or off
function SetupLaserDot ()
{
if ( bDotActive )
{
//if we want a laserdot, and we don't already have one, then create one
if (LaserDot == None)
{
LaserDot = Spawn(class'LaserDot', Self, , Location, Rotation);
}
}
else
{
//destroy the laserdot
DestroyLaserDot();
}
}

// This flag prevents from changing the AWO during a weapon swich
function DownWeapon()
{
bIsChanging=true;
}

// Toggles laser dot on/off
Function ChangeDot()
{
bDotActive = !bDotActive;
SetupLaserDot();
}

simulated function Tick(float deltatime)
{
// client side stuff here
TickTimer += DeltaTime;
if (TickTimer > 0.3)
{
TickTimer=0.0;
bFlash = !bFlash;
}

//remove the laserdot if our owner died
if ( Instigator == None )
DestroyLaserDot();
Super.Tick(deltatime);

// Check here to make sure that we did not loose the controller
// Say the player entered a vehicle..then we should disable the dot
if( Role==ROLE_Authority && Instigator.Controller == None && bDotActive)
ChangeDot();
}

simulated function BringUp(optional Weapon PrevWeapon)
{

// Turn on the laserdot
if( Role==ROLE_Authority )
{
bDotActive=true;
SetupLaserDot();
}
bIsChanging=false;
Super.BringUp();
}

simulated function bool PutDown()
{
DownWeapon();
if( Instigator.Controller.IsA( 'PlayerController' ) )
PlayerController(Instigator.Controller).EndZoom();
// Remove the laser dot if the put down their weapon
if( LaserDot != none)
ChangeDot();
if ( Super.PutDown() ) {
GotoState('');
return true;
}
return false;
}
jb
Posts: 9825
Joined: Fri May 03, 2002 12:29 am
Location: Coral Springs, FL
Contact:

Post by jb »

Ahhh

you have to move the laser dot and thats done in the snipers weapon fire code (CUTRifleFire.uc):


Code: Select all

//this function will move the laser dot to what ever we are looking at
function ModeTick(float dt)
{
    local Vector StartTrace, EndTrace, X,Y,Z;
    local Vector HitLocation, HitNormal;
    local Actor Other;
    local Rotator Aim;
    Local CUTRifle Sniper;


    Sniper = CUTRifle(Weapon);
    if(Sniper != none && !Sniper.bDotActive)
      return; // Dot is not active so dont draw it

    Weapon.GetViewAxes(X,Y,Z);

    // the to-hit trace always starts right in front of the eye
    StartTrace = Instigator.Location + Instigator.EyePosition() + X*Instigator.CollisionRadius;
    if (Instigator.controller.pawn.IsA('Vehicle'))
    {
       Sniper.DestroyLaserDot();
       return;
    }
    Aim = AdjustAim(StartTrace, AimError);
    X = Vector(Aim);
    EndTrace = StartTrace + 20000 * X;

    Other = Trace(HitLocation, HitNormal, EndTrace, StartTrace, true);

    if (Other != None && Sniper!= None && Sniper.LaserDot != None && Sniper.bDotActive)
    {
    	//move the laser dot to  location
        Sniper.LaserDot.SetLocation(HitLocation);
		Sniper.LaserDot.SetRotation(Rotator(HitNormal));
    }
    else if (other == None && Sniper!= None && Sniper.LaserDot != None && Sniper.bDotActive)
    {
        //move the laser dot to this location and this rotation
		Sniper.LaserDot.SetLocation(EndTrace);
        Sniper.LaserDot.SetRotation(Rotator(EndTrace - StartTrace));
    }

}
Jb
UndeadRoadkill
Posts: 5
Joined: Sun Jun 19, 2005 2:51 am

Post by UndeadRoadkill »

I tried making my own weaponfire using that bit of code, but it still behaves the same way, i.e. spawns the dot at my location and leaves it there. Is there anything else I'm leaving out?
jb
Posts: 9825
Joined: Fri May 03, 2002 12:29 am
Location: Coral Springs, FL
Contact:

Post by jb »

Need to see your weapon fire code to make sure....
Jb
UndeadRoadkill
Posts: 5
Joined: Sun Jun 19, 2005 2:51 am

Post by UndeadRoadkill »

Here is the code from the weaponfire:

Code: Select all

class SGOMPXFire extends SGOMPSFire
	placeable;


//this function will move the laser dot to what ever we are looking at
function ModeTick(float dt)
{
    local Vector StartTrace, EndTrace, X,Y,Z;
    local Vector HitLocation, HitNormal;
    local Actor Other;
    local Rotator Aim;
    Local CUTRifle Sniper;


    Sniper = CUTRifle(Weapon);
    if(Sniper != none && !Sniper.bDotActive)
      return; // Dot is not active so dont draw it

    Weapon.GetViewAxes(X,Y,Z);

    // the to-hit trace always starts right in front of the eye
    StartTrace = Instigator.Location + Instigator.EyePosition() + X*Instigator.CollisionRadius;
    if (Instigator.controller.pawn.IsA('Vehicle'))
    {
       Sniper.DestroyLaserDot();
       return;
    }
    Aim = AdjustAim(StartTrace, AimError);
    X = Vector(Aim);
    EndTrace = StartTrace + 20000 * X;

    Other = Trace(HitLocation, HitNormal, EndTrace, StartTrace, true);

    if (Other != None && Sniper!= None && Sniper.LaserDot != None && Sniper.bDotActive)
    {
    	//move the laser dot to  location
        Sniper.LaserDot.SetLocation(HitLocation);
		Sniper.LaserDot.SetRotation(Rotator(HitNormal));
    }
    else if (other == None && Sniper!= None && Sniper.LaserDot != None && Sniper.bDotActive)
    {
        //move the laser dot to this location and this rotation
		Sniper.LaserDot.SetLocation(EndTrace);
        Sniper.LaserDot.SetRotation(Rotator(EndTrace - StartTrace));
    }

}
jb
Posts: 9825
Joined: Fri May 03, 2002 12:29 am
Location: Coral Springs, FL
Contact:

Post by jb »

You got caught buy they good ol type casting issue..

Look closer to you code:


Local CUTRifle Sniper;

Sniper = CUTRifle(Weapon);
if(Sniper != none && !Sniper.bDotActive)
return; // Dot is not active so dont draw it
...
For your code this will always be none:

Sniper = CUTRifle(Weapon);

Beacuse your weapon is not of type CUTRifle. Changing all cases of CUTRifle in your code with SGOMPX should fixed it for you... :)
Jb
UndeadRoadkill
Posts: 5
Joined: Sun Jun 19, 2005 2:51 am

Post by UndeadRoadkill »

Ah, that fixed it! Thank you very much for your patience and help, I appreciate it!
jb
Posts: 9825
Joined: Fri May 03, 2002 12:29 am
Location: Coral Springs, FL
Contact:

Post by jb »

Yea
Jb
Loki
Posts: 21
Joined: Sat Jun 04, 2005 5:36 pm

Post by Loki »

Minigun with the laser sight.... mm...

...er.. sorry. :oops:
Post Reply