Announcement

Collapse
No announcement yet.

[Help]: Making a minigun turret's barrel spin without animations.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [Help]: Making a minigun turret's barrel spin without animations.

    I need help making a minigun turret's barrels spin while firing without an animation. So far I've tried adding:
    Code:
    simulated function PostBeginPlay()
    {
    	local Rotator	R;
    
    	super.PostBeginPlay();
    
    	 R					= GetBoneRotation( 'Cannons' );
    	 CurrentCannonRoll	= R.Yaw;
    }
    
    /*
    Firing state:
    Updates cannon rotation
    */
    state Firing
    {
        simulated function Tick(float deltaTime)
        {
    		local rotator	R;
    
    		if ( Instigator == None )
    			return;
    
    		if ( bWeaponIsFiring && (Level.TimeSeconds - LastFireTime > 0.5) )
    			StopFiring();
    
    		if ( bWeaponIsFiring )
    		{ 
    			// Increase rotation rate...
    			if ( CurrentRollSpeed < CannonRollSpeed )
    				CurrentRollSpeed += RollSpeedAcc * 4.f * deltaTime;	// faster acceleration when shooting
    			else if ( CurrentRollSpeed > CannonRollSpeed )
    				CurrentRollSpeed = CannonRollSpeed;
    		}
    		else
    		{	
    			// decrease rotation rate...
    			if ( CurrentRollSpeed > 0 )
    				CurrentRollSpeed -= RollSpeedAcc * deltaTime;
    			
    			// If rotation rate is null, exit state..
    			if ( CurrentRollSpeed < 0 )
    			{
    				CurrentRollSpeed = 0;
    				GotoState('');
    			}
    		}
    
    		// Rotating cannon
    		CurrentCannonRoll = (CurrentCannonRoll + CurrentRollSpeed * deltatime) % 65536;
    		R.Roll = CurrentCannonRoll;
    		Instigator.SetBoneRotation('Cannons', R, 0, 1.f);
        }
    
    }
    
    simulated Event StartFiring()
    {
    	bWeaponIsFiring	= true;
    	
    //	if ( Instigator != None )
    //		Instigator.AmbientSound	= FiringSound;
    
    	GotoState('Firing');
    }
    
    simulated function vector GetFireStart( vector RelOffset )
    {
    	local vector	X, Y, Z;
    
    	GetViewAxes(X, Y, Z);
        return Instigator.Location + X*RelOffset.X + Y*RelOffset.Y + Z*RelOffset.Z;
    }
    
    simulated function GetViewAxes( out vector xaxis, out vector yaxis, out vector zaxis )
    {
    	GetAxes( Instigator.Rotation, xaxis, yaxis, zaxis );
    }
    
    simulated Event StopFiring()
    {
    	if ( !bWeaponIsFiring )
    		return;
    
    	bFiring	= false;
    }
    to the vehicle's weapon pawn and:
    Code:
     
    simulated function PostBeginPlay()
    {
    	local Rotator	R;
    
    	super.PostBeginPlay();
    
    	 R					= GetBoneRotation( 'Cannons' );
    	 CurrentCannonRoll	= R.Yaw;
    }
    
    /*
    Firing state:
    Updates cannon rotation
    */
    state Firing
    {
        simulated function Tick(float deltaTime)
        {
    		local rotator	R;
    
    		if ( Instigator == None )
    			return;
    
    		if ( bIsRepeatingFF && (Level.TimeSeconds - LastFireTime > 0.5) )
    			StopFiring();
    
    		if ( bIsRepeatingFF )
    		{ 
    			// Increase rotation rate...
    			if ( CurrentRollSpeed < CannonRollSpeed )
    				CurrentRollSpeed += RollSpeedAcc * 4.f * deltaTime;	// faster acceleration when shooting
    			else if ( CurrentRollSpeed > CannonRollSpeed )
    				CurrentRollSpeed = CannonRollSpeed;
    		}
    		else
    		{	
    			// decrease rotation rate...
    			if ( CurrentRollSpeed > 0 )
    				CurrentRollSpeed -= RollSpeedAcc * deltaTime;
    			
    			// If rotation rate is null, exit state..
    			if ( CurrentRollSpeed < 0 )
    			{
    				CurrentRollSpeed = 0;
    				GotoState('');
    			}
    		}
    
    		// Rotating cannon
    		CurrentCannonRoll = (CurrentCannonRoll + CurrentRollSpeed * deltatime) % 65536;
    		R.Roll = CurrentCannonRoll;
    		Instigator.SetBoneRotation('Cannons', R, 0, 1.f);
        }
    
    }
    
    
    simulated Event StartFiring()
    {
    	bIsRepeatingFF	= true;
    	
    //	if ( Instigator != None )
    //		Instigator.AmbientSound	= FiringSound;
    
    	GotoState('Firing');
    }
    
    simulated function vector GetFireStart( vector RelOffset )
    {
    	local vector	X, Y, Z;
    
    	GetViewAxes(X, Y, Z);
        return Instigator.Location + X*RelOffset.X + Y*RelOffset.Y + Z*RelOffset.Z;
    }
    
    simulated function GetViewAxes( out vector xaxis, out vector yaxis, out vector zaxis )
    {
    	GetAxes( Instigator.Rotation, xaxis, yaxis, zaxis );
    }
    
    simulated Event StopFiring()
    {
    	if ( !bFiring )
    		return;
    
    	bIsRepeatingFF	= false;
    }
    to my vehicle's weapon with no effect. (code adapted from the AS minigun turret)
    btw-I havent gotten any odd messages in the log file and the bone name is correct.

    #2
    Stick in some debug lines. Some people like using the log for that:
    Code:
    Log("this is written in the log");
    I like broadcasting them:
    Code:
    Level.Game.Broadcast(Instigator.Controller, "this is broadcasted in the chat", 'Say');
    Try to figure out 1) if the functions are being called at all, 2) what rotation is calculated, 3) if the rotation is being applied.

    Comment


      #3
      ^Thanks agin Xyx, it turns out none of it was being called. :bulb: :sigh: I'll double check the ons source code to see if I'm using the right function.

      Comment

      Working...
      X