Results 1 to 15 of 15
  1. #1
    MSgt. Shooter Person
    Join Date
    Jun 2012
    Posts
    68

    Default Change state from flying to phys_Spider

    I'm trying to implement a landing physic in my game. So far I've got it to compile without errors, but it won't work. I even have it set up in my default input and is bound to F.

    Here's my player controller:

    Code:
    class SH2GamePlayerController extends UTPlayerController;
    
    var Rotator aRotLocal;
    var float aRollLocal;
    const rollAmount = 300;
    var int traceDistance;
    var Quat QuatRotation;
    var vector CameraOffset;
    
    	simulated event GetPlayerViewPoint(out vector POVLocation, out Rotator POVRotation)
    	{
    	    super.GetPlayerViewPoint(POVLocation, POVRotation);
    	
    	    if(Pawn != none)
    	    {
    	        POVLocation = Pawn.Location + (CameraOffset >> Pawn.Rotation);
    	        POVRotation = Pawn.Rotation;
    	    }
    	}
    
    
    //////////////////////////////////
    
    	exec function PlayerRollLeftStart() {
    		`log("PlayerRollLeft called");
    		aRollLocal -= rollAmount;
    	}
    	
    	exec function PlayerRollLeftEnd() {
    		aRollLocal = 0;
    	}
    	
    	exec function PlayerRollRightStart() {
    		`log("PlayerRollRight called");
    		aRollLocal += rollAmount;
    	}
    
    	exec function PlayerRollRightEnd() {
    		aRollLocal = 0;
    	}
    
    //////////////////////////////////
    
    	simulated function PostBeginPlay()
    	{  
    	     super.PostBeginPlay(); 
    		QuatRotation = QuatFromAxisAndAngle( Vect(1,0,0), 0.0 ); 
    	
    		traceDistance = 200;
    	
    		Pawn.SetPhysics(PHYS_Flying);
    	
    	}
    	
    //////////////////////////////////
    	function UpdateRotation( float DeltaTime )
    	{
    		local Rotator DeltaRot, newRotation, ViewRotation;
    		local float aRollAbstract, aTurnAbstract, aLookUpAbstract;
    		local Quat RotQuat; 
    		aRollAbstract = aRollLocal * 0.005;
    		aTurnAbstract = PlayerInput.aTurn * 0.005;
    		aLookUpAbstract = PlayerInput.aLookUp * -0.005;
    	
    		
    
    		// Roll
    		RotQuat = QuatFromAxisAndAngle( vect(1,0,0), DeltaTime * aRollAbstract );
    		QuatRotation = QuatProduct(QuatRotation, RotQuat);
    	 
    		// Yaw
    		RotQuat = QuatFromAxisAndAngle( vect(0,0,1), DeltaTime * aTurnAbstract );
    		QuatRotation = QuatProduct(QuatRotation, RotQuat);
    		 
    		// Pitch
    		RotQuat = QuatFromAxisAndAngle( vect(0,1,0), DeltaTime * aLookUpAbstract );
    		QuatRotation = QuatProduct(QuatRotation, RotQuat);
    	
    
    		//ViewRotation = Rotation;
    		ViewRotation = QuatToRotator(QuatRotation);
    		if (Pawn!=none)
    		{
    			Pawn.SetDesiredRotation(ViewRotation);
    		}
    
    	
    		ProcessViewRotation( DeltaTime, ViewRotation, DeltaRot );
    		SetRotation(ViewRotation);
    
    		ViewShake( deltaTime );
    
    		NewRotation = ViewRotation;
    		NewRotation.Roll = Rotation.Roll;
    
    		if ( Pawn != None )
    			Pawn.FaceRotation(NewRotation, deltatime);
    
    	}
    
    
    
    //////////////////////////////////
    
    state PlayerSpidering
    {
    	simulated function PostBeginPlay()
    	{  
    	     super.PostBeginPlay(); 
    		QuatRotation = QuatFromAxisAndAngle( Vect(1,0,0), 0.0 ); 
    	
    		traceDistance = 200;
    	
    		Pawn.SetPhysics(PHYS_Spider);
    	
    	}
    }
    //////////////////////////////////
    
    defaultproperties
    {
    	InputClass=class'SH2GameInput'
    	CameraOffset=(Z=30),(X=5)
    	//bCollideAsEncroacher = true;
    
    }
    And the line i entered in to my default input:

    Code:
    .Bindings=(Name="F", command="state PlayerSpidering")
    NOTE: I'm not sure if this will affect anything, but in my pawn, to allow my player to fly properly, I have this line:
    Code:
    LandMovementState=PlayerFlying

  2. #2
    MSgt. Shooter Person
    Join Date
    Jul 2011
    Location
    Shanghai
    Posts
    309

    Default

    How do you expect PostBeginPlay() in the state PlayerSpidering to be called when PlayerSpidering isn't the initial state, and even if it was, SetInitialState() is called after PostBeginPlay()?
    Last edited by evr; 08-03-2012 at 04:26 AM.

  3. #3
    MSgt. Shooter Person
    Join Date
    Jun 2012
    Posts
    68

    Default

    Everything else I have tried thus far has not compiled at all.

  4. #4
    MSgt. Shooter Person
    Join Date
    Jul 2011
    Location
    Shanghai
    Posts
    309

    Default

    From reading the code I'm not sure exactly what you want to do. Do you just want to change Pawn's physics to PHYS_Spider?

  5. #5
    MSgt. Shooter Person
    Join Date
    Jun 2012
    Posts
    68

    Default

    Yes. i want to be able to walk on walls at the press of a button.

  6. #6
    MSgt. Shooter Person
    Join Date
    Jul 2011
    Location
    Shanghai
    Posts
    309

    Default

    Looks like it's covered at http://forums.epicgames.com/archive/.../t-714381.html. I'd look into the UT2003 code for PHYS_Spider and port it.

  7. #7
    MSgt. Shooter Person
    Join Date
    Jun 2012
    Posts
    68

    Default

    Alright, i got the source file from here: http://www.gamefront.com/files/servi...you?id=4379255

    Any clue as to where it is?

  8. #8
    MSgt. Shooter Person
    Join Date
    Jul 2011
    Location
    Shanghai
    Posts
    309

    Default

    Looks like that's the Unreal source.

    Here you go: http://www.gamefront.com/files/37960...225_source_zip

    /Engine/Classes/PlayerController.uc - state PlayerSpidering

  9. #9
    MSgt. Shooter Person
    Join Date
    Jun 2012
    Posts
    68

    Default

    Alright. I updated my code with the Phys_Spider, but my if statement is having some problems

    Code:
     if ( (Pawn.Base == None) || (Pawn.Floor == vect(0,0,0)) )
    Here's the compiler warning:


    And the updated code:
    Code:
    class SH2GamePlayerController extends UTPlayerController;
    
    var Rotator aRotLocal;
    var float aRollLocal;
    const rollAmount = 300;
    var int traceDistance;
    var Quat QuatRotation;
    var vector CameraOffset;
    var vector OldFloor;
    var vector ViewX,ViewY,ViewZ;
    
    	simulated event GetPlayerViewPoint(out vector POVLocation, out Rotator POVRotation)
    	{
    	    super.GetPlayerViewPoint(POVLocation, POVRotation);
    	
    	    if(Pawn != none)
    	    {
    	        POVLocation = Pawn.Location + (CameraOffset >> Pawn.Rotation);
    	        POVRotation = Pawn.Rotation;
    	    }
    	}
    
    
    //////////////////////////////////
    
    	exec function PlayerRollLeftStart() {
    		`log("PlayerRollLeft called");
    		aRollLocal -= rollAmount;
    	}
    	
    	exec function PlayerRollLeftEnd() {
    		aRollLocal = 0;
    	}
    	
    	exec function PlayerRollRightStart() {
    		`log("PlayerRollRight called");
    		aRollLocal += rollAmount;
    	}
    
    	exec function PlayerRollRightEnd() {
    		aRollLocal = 0;
    	}
    
    //////////////////////////////////
    
    	simulated function PostBeginPlay()
    	{  
    	     super.PostBeginPlay(); 
    		QuatRotation = QuatFromAxisAndAngle( Vect(1,0,0), 0.0 ); 
    	
    		traceDistance = 200;
    	
    		Pawn.SetPhysics(PHYS_Flying);
    	
    	}
    	
    //////////////////////////////////
    	function UpdateRotation( float DeltaTime )
    	{
    		local Rotator DeltaRot, newRotation, ViewRotation;
    		local float aRollAbstract, aTurnAbstract, aLookUpAbstract;
    		local Quat RotQuat; 
    		aRollAbstract = aRollLocal * 0.005;
    		aTurnAbstract = PlayerInput.aTurn * 0.005;
    		aLookUpAbstract = PlayerInput.aLookUp * -0.005;
    	
    		
    
    		// Roll
    		RotQuat = QuatFromAxisAndAngle( vect(1,0,0), DeltaTime * aRollAbstract );
    		QuatRotation = QuatProduct(QuatRotation, RotQuat);
    	 
    		// Yaw
    		RotQuat = QuatFromAxisAndAngle( vect(0,0,1), DeltaTime * aTurnAbstract );
    		QuatRotation = QuatProduct(QuatRotation, RotQuat);
    		 
    		// Pitch
    		RotQuat = QuatFromAxisAndAngle( vect(0,1,0), DeltaTime * aLookUpAbstract );
    		QuatRotation = QuatProduct(QuatRotation, RotQuat);
    	
    
    		//ViewRotation = Rotation;
    		ViewRotation = QuatToRotator(QuatRotation);
    		if (Pawn!=none)
    		{
    			Pawn.SetDesiredRotation(ViewRotation);
    		}
    
    	
    		ProcessViewRotation( DeltaTime, ViewRotation, DeltaRot );
    		SetRotation(ViewRotation);
    
    		ViewShake( deltaTime );
    
    		NewRotation = ViewRotation;
    		NewRotation.Roll = Rotation.Roll;
    
    		if ( Pawn != None )
    			Pawn.FaceRotation(NewRotation, deltatime);
    
    	}
    
    
    
    //////////////////////////////////
    
    state PlayerSpidering
    {
    ignores SeePlayer, HearNoise, Bump;
    
        event bool NotifyHitWall(vector HitNormal, actor HitActor)
        {
            Pawn.SetPhysics(PHYS_Spider);
            Pawn.SetBase(HitActor, HitNormal);
            return true;
        }
    
        // if spider mode, update rotation based on floor
        function UpdateRotational(float DeltaTime, float maxPitch)
        {
            local rotator ViewRotation;
            local vector MyFloor, CrossDir, FwdDir, OldFwdDir, OldX, RealFloor;
    
    
            if ( (Pawn.Base == None) || (Pawn.Floor == vect(0,0,0)) )
                MyFloor = vect(0,0,1);
            else
                MyFloor = Pawn.Floor;
    
            if ( MyFloor != OldFloor )
            {
                // smoothly change floor
                RealFloor = MyFloor;
                MyFloor = Normal(6*DeltaTime * MyFloor + (1 - 6*DeltaTime) * OldFloor);
                if ( (RealFloor Dot MyFloor) > 0.999 )
                    MyFloor = RealFloor;
    
                // translate view direction
                CrossDir = Normal(RealFloor Cross OldFloor);
                FwdDir = CrossDir Cross MyFloor;
                OldFwdDir = CrossDir Cross OldFloor;
                ViewX = MyFloor * (OldFloor Dot ViewX)
                            + CrossDir * (CrossDir Dot ViewX)
                            + FwdDir * (OldFwdDir Dot ViewX);
                ViewX = Normal(ViewX);
    
                ViewZ = MyFloor * (OldFloor Dot ViewZ)
                            + CrossDir * (CrossDir Dot ViewZ)
                            + FwdDir * (OldFwdDir Dot ViewZ);
                ViewZ = Normal(ViewZ);
                OldFloor = MyFloor;
                ViewY = Normal(MyFloor Cross ViewX);
            }
    
            if ( (aTurn != 0) || (aLookUp != 0) )
            {
                // adjust Yaw based on aTurn
                if ( aTurn != 0 )
                    ViewX = Normal(ViewX + 2 * ViewY * Sin(0.0005*DeltaTime*aTurn));
    
                // adjust Pitch based on aLookUp
                if ( aLookUp != 0 )
                {
                    OldX = ViewX;
                    ViewX = Normal(ViewX + 2 * ViewZ * Sin(0.0005*DeltaTime*aLookUp));
                    ViewZ = Normal(ViewX Cross ViewY);
    
                    // bound max pitch
                    if ( (ViewZ Dot MyFloor) < 0.707   )
                    {
                        OldX = Normal(OldX - MyFloor * (MyFloor Dot OldX));
                        if ( (ViewX Dot MyFloor) > 0)
                            ViewX = Normal(OldX + MyFloor);
                        else
                            ViewX = Normal(OldX - MyFloor);
    
                        ViewZ = Normal(ViewX Cross ViewY);
                    }
                }
    
                // calculate new Y axis
                ViewY = Normal(MyFloor Cross ViewX);
            }
            ViewRotation =  OrthoRotation(ViewX,ViewY,ViewZ);
            SetRotation(ViewRotation);
            ViewShake(deltaTime);
            ViewFlash(deltaTime);
            Pawn.FaceRotation(ViewRotation, deltaTime );
        }
    
        function bool NotifyLandedNow(vector HitNormal)
        {
            Pawn.SetPhysics(PHYS_Spider);
            return bUpdating;
        }
    }
    //////////////////////////////////
    
    defaultproperties
    {
    	InputClass=class'SH2GameInput'
    	CameraOffset=(Z=30),(X=5)
    	//bCollideAsEncroacher = true;
    
    }

  10. #10
    MSgt. Shooter Person
    Join Date
    Jun 2012
    Posts
    68

    Default

    Alright, I commented that entire segment of code out and It's compiling fine. However, it's still not working.

  11. #11
    MSgt. Shooter Person
    Join Date
    Jul 2011
    Location
    Shanghai
    Posts
    309

    Default

    Where do you change the state to PlayerSpidering?

  12. #12
    MSgt. Shooter Person
    Join Date
    Jun 2012
    Posts
    68

    Default

    I set the default input for the binding. I'm not good at unrealscript.

  13. #13
    MSgt. Shooter Person
    Join Date
    Jul 2011
    Location
    Shanghai
    Posts
    309

    Default

    That's okay. What I suspect the error was about is the variable OldFloor which exist in the original PlayerController.uc you copied the code from. Look it up in that file and copy-paste the declaration to your own playercontroller. It should compile after that.

    As for changing the state, try using an exec function to begin with.

    Code:
    exec function ChangeToSpider()
    {
    	GotoState('PlayerSpidering');
    }
    Then bind any key you want to execute that function. Example:

    Code:
    .Bindings=(Name="F", command="ChangeToSpider")

  14. #14
    MSgt. Shooter Person
    Join Date
    Jun 2012
    Posts
    68

    Default

    Alright, so it compile but when I press F it just locks all my controls. i can't turn, or even strafe.

  15. #15
    MSgt. Shooter Person
    Join Date
    Dec 2010
    Posts
    55

    Default

    Quote Originally Posted by Danson Delta-40 View Post
    Alright, so it compile but when I press F it just locks all my controls. i can't turn, or even strafe.
    That's because your PlayerSpidering state doesn't define the PlayerMove function. As you can see, its calling the global version of PlayerMove(), which is just a stub function (etc it has no implementation). Basically, you need to define the PlayerMove function in your PlayerSpidering state, and implement how your Pawn should move.

    Another thing is that UpdateRotation() is usually called from PlayerMove() as you can see from the other states. If you binded those exec functions to keys, then you'd have to come up with a way to call UpdateRotation().
    Last edited by joe.d-s; 08-05-2012 at 11:56 PM.


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.