Announcement

Collapse
No announcement yet.

Relative Physics Problem

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

    @elhant1

    if i separate the following PZ commands for the roll pitch and yaw, UDK will read them as bad expressions.
    Code:
    class UTVehicle_SpaceShip extends UTAirVehicle;
    
    /* etc */ 
    
    var float AR_MaxLift, AR_TurnSpeed, AR_Speed, AR_CurrentForward, AR_AddedLiftSpeed, AR_Acceleration;
    
    /* etc */
    
    simulated function AirRaidKinematics(float DeltaTime)
    {
    	local Vector AR_ForceApplication, AR_ForceRotation, AR_ForwardsNormal, AR_UpwardsNormal, AR_SidewardsNormal;
    	local Vector AR_ForceRotationVectX, AR_ForceRotationVectY, AR_ForceRotationVectZ;
    	local float AR_Lift, AR_ForwardSpeed, AR_NewRise;
    
    	// While there is a player in the biplane:
    	if (PlayerController(Controller) != None)
    	{
    		GetAxes(Rotation, AR_ForwardsNormal, AR_SidewardsNormal, AR_UpwardsNormal);
    		
    		// Roll 
    PZ_ForceRotationVectX *= 800 * Rise; // PZ_NewRise is between -1 and 1
    
    		// Pitch 
    PZ_ForceRotationVectY *= 30 * -PlayerController(Controller).PlayerInput.aMouseY / 100;
    
    		// Yaw 
    PZ_ForceRotationVectZ *= 30 * PlayerController(Controller).PlayerInput.aMouseX / 100;
    
    		// The magic happens here ---- Forward 
    PZ_ForceApplication = PZ_ForwardsNormal * Throttle * 6000;
    
    		AR_CurrentForward += AR_Acceleration * Throttle;
    		AR_ForwardSpeed = AR_CurrentForward * 2.2;
    		// AR_ForwardSpeed is not necessarily true - I'd optimally need to use some 
    		// calculation based off Velocity and current forwards direction Vector...
    
    		// Calculate lift for the biplane:
    		AR_Lift = (AR_ForwardSpeed + AR_AddedLiftSpeed) * Abs(Cos(Rotation.Pitch));
    		if (AR_Lift > AR_MaxLift) AR_Lift = AR_MaxLift;
    		
    		// This gives lift upwards relative to its up-axis and push forwards relative to its forward-axis:
    		AR_ForceApplication.X = AR_UpwardsNormal.X * AR_Lift + AR_CurrentForward * AR_ForwardsNormal.X;
    		AR_ForceApplication.Y = AR_UpwardsNormal.Y * AR_Lift + AR_CurrentForward * AR_ForwardsNormal.Y;
    		AR_ForceApplication.Z = AR_UpwardsNormal.Z * AR_Lift + AR_CurrentForward * AR_ForwardsNormal.Z;
    		
    		// Add forces and rotations
    		Mesh.AddForce(AR_ForceApplication);
    		Mesh.AddTorque(AR_ForceRotation);
    
    	}
    	else
    	{
    		AR_CurrentForward = AR_Speed; // Biplane propellor thrust sets to default
    	}
    }
    
    
    simulated function Tick(float DeltaTime)
    {
    	AirRaidKinematics(DeltaTime);
    	Super.Tick(DeltaTime);
    }
    
    /* etc */
    defaultproperties
    {
    	Begin Object Class=UDKVehicleSimChopper Name=SimObject
    		MaxThrustForce=700.0
    		MaxReverseForce=700.0
    		LongDamping=0.6
    		MaxStrafeForce=680.0
    		LatDamping=0.7
    		MaxRiseForce=1000.0
    		UpDamping=0.7
    		TurnTorqueFactor=7000.0
    		TurnTorqueMax=10000.0
    		TurnDamping=1.2
    		MaxYawRate=1.8
    		PitchTorqueFactor=450.0
    		PitchTorqueMax=60.0
    		PitchDamping=0.3
    		RollTorqueTurnFactor=700.0
    		RollTorqueStrafeFactor=100.0
    		RollTorqueMax=300.0
    		RollDamping=0.1
    		MaxRandForce=30.0
    		RandForceInterval=0.5
    		StopThreshold=100
    		bShouldCutThrustMaxOnImpact=true
    	End Object
    	SimObj=SimObject
    	Components.Add(SimObject)
    
    	COMOffset=(X=-40,Z=-50.0)
    
    	BaseEyeheight=30
    	Eyeheight=30
    	bRotateCameraUnderVehicle=false
    	CameraLag=0.05
    	LookForwardDist=290.0
    	bLimitCameraZLookingUp=true
    
    	AirSpeed=2000.0
    	GroundSpeed=1600.0
    
    	UprightLiftStrength=30.0
    	UprightTorqueStrength=30.0
    
    	bStayUpright=true
    	StayUprightRollResistAngle=5.0
    	StayUprightPitchResistAngle=5.0
    	StayUprightStiffness=1200
    	StayUprightDamping=20
    	
    	bRollToDesired = true // ## VITAL CODE: enables rolling of the pawn
    	AirSpeed = 380.0 // maximum speed
    	AccelRate = 800.0 // acceleration speed
    
    	SpawnRadius=180.0
    	RespawnTime=45.0
    
    	bOverrideAVRiLLocks=true
    
    	PushForce=50000.0
    	HUDExtent=140.0
    
    	HornIndex=0
    }
    I dont see anything wrong with this now but UDK still doesnt read these codes correctly. The PZ commands always shows up as bad expression..
    Maybe you could suggest a better coding for my vehicle.uc? maybe i should delete some of those? And yes, its for the mouse.

    Comment


      Well, if you don't have a valid declaration for a variable or it's not in the right scope, US's compiler, like most languages' can't find them and will give you errors and abort immediately.

      Where have you declared variables PZ_Force* ? Post that part of your code.

      Comment


        Ok. I have no idea to fix it but I think I have another idea. In the Defaultinput try to change the bindings to link mouse input to gbaduck,jump,strateleft,strateright...
        I'm not sure if it's what you want and if it's possible.

        No idea for my problem?

        Comment


          local Vector AR_ForceApplication, AR_ForceRotation, AR_ForwardsNormal, AR_UpwardsNormal, AR_SidewardsNormal;
          local Vector AR_ForceRotationVectX, AR_ForceRotationVectY, AR_ForceRotationVectZ;
          local float AR_Lift, AR_ForwardSpeed, AR_NewRise;

          only AR you have don't change to PZ ?

          Comment


            Originally posted by Hiredicespecter View Post
            The lines with PZ_ should start with AR_, because you have not declared any variable whose name starts with PZ_. The code pieces in this thread aren't taken from the same code base, sorry about that.

            Code:
            // Roll 
            AR_ForceRotationVectX *= 800 * Rise;
            
            // Pitch 
            AR_ForceRotationVectY *= 30 * -PlayerController(Controller).PlayerInput.aMouseY / 100;
            
            // Yaw 
            AR_ForceRotationVectZ *= 30 * PlayerController(Controller).PlayerInput.aMouseX / 100;
            
            // The magic happens here ---- Forward 
            AR_ForceApplication = AR_ForwardsNormal * Throttle * 6000;
            The PZ_ lines are supposed to replace the matching lines the AR_.

            A good UnrealScript tutorial can be found here: http://www.4r7w4re.com/
            Ok, I'll try to replace PZ with AR, and see if it works....

            Comment


              Originally posted by elhant1 View Post
              Ok. I have no idea to fix it but I think I have another idea. In the Defaultinput try to change the bindings to link mouse input to gbaduck,jump,strateleft,strateright...
              I'm not sure if it's what you want and if it's possible.

              No idea for my problem?
              If i change my mouse input to that, will my camera still move while my vehicle is moving?

              Comment


                Originally posted by deguitz06 View Post
                Ok, I'll try to replace PZ with AR, and see if it works....
                Now my vehicle.uc looks like this,

                Code:
                class UTVehicle_Spaceship extends UTAirVehicle;
                
                /* etc */ 
                
                var float AR_MaxLift, AR_TurnSpeed, AR_Speed, AR_CurrentForward, AR_AddedLiftSpeed, AR_Acceleration;
                
                /* etc */
                
                simulated function AirRaidKinematics(float DeltaTime)
                {
                	local Vector AR_ForceApplication, AR_ForceRotation, AR_ForwardsNormal, AR_UpwardsNormal, AR_SidewardsNormal;
                	local Vector AR_ForceRotationVectX, AR_ForceRotationVectY, AR_ForceRotationVectZ;
                	local float AR_Lift, AR_ForwardSpeed, AR_NewRise;
                
                	// While there is a player in the biplane:
                	if (PlayerController(Controller) != None)
                	{
                		GetAxes(Rotation, AR_ForwardsNormal, AR_SidewardsNormal, AR_UpwardsNormal);
                		
                		// Roll 
                AR_ForceRotationVectX *= 800 * Rise; // PZ_NewRise is between -1 and 1
                
                		// Pitch 
                AR_ForceRotationVectY *= 30 * -PlayerController(Controller).PlayerInput.aMouseY / 100;
                
                		// Yaw
                AR_ForceRotationVectZ *= 30 * PlayerController(Controller).PlayerInput.aMouseX / 100;
                
                		// The magic happens here ---- Forward 
                AR_ForceApplication = AR_ForwardsNormal * Throttle * 6000;
                
                		AR_CurrentForward += AR_Acceleration * Throttle;
                		AR_ForwardSpeed = AR_CurrentForward * 2.2;
                		// AR_ForwardSpeed is not necessarily true - I'd optimally need to use some 
                		// calculation based off Velocity and current forwards direction Vector...
                
                		// Calculate lift for the biplane:
                		AR_Lift = (AR_ForwardSpeed + AR_AddedLiftSpeed) * Abs(Cos(Rotation.Pitch));
                		if (AR_Lift > AR_MaxLift) AR_Lift = AR_MaxLift;
                		
                		// This gives lift upwards relative to its up-axis and push forwards relative to its forward-axis:
                		AR_ForceApplication.X = AR_UpwardsNormal.X * AR_Lift + AR_CurrentForward * AR_ForwardsNormal.X;
                		AR_ForceApplication.Y = AR_UpwardsNormal.Y * AR_Lift + AR_CurrentForward * AR_ForwardsNormal.Y;
                		AR_ForceApplication.Z = AR_UpwardsNormal.Z * AR_Lift + AR_CurrentForward * AR_ForwardsNormal.Z;
                		
                		// Add forces and rotations
                		Mesh.AddForce(AR_ForceApplication);
                		Mesh.AddTorque(AR_ForceRotation);
                
                	}
                	else
                	{
                		AR_CurrentForward = AR_Speed; // Biplane propellor thrust sets to default
                	}
                }
                
                
                simulated function Tick(float DeltaTime)
                {
                	AirRaidKinematics(DeltaTime);
                	Super.Tick(DeltaTime);
                }
                
                /* etc */
                defaultproperties
                {
                	Begin Object Class=UDKVehicleSimChopper Name=SimObject
                		MaxThrustForce=700.0
                		MaxReverseForce=700.0
                		LongDamping=0.6
                		MaxStrafeForce=680.0
                		LatDamping=0.7
                		MaxRiseForce=1000.0
                		UpDamping=0.7
                		TurnTorqueFactor=7000.0
                		TurnTorqueMax=10000.0
                		TurnDamping=1.2
                		MaxYawRate=1.8
                		PitchTorqueFactor=450.0
                		PitchTorqueMax=60.0
                		PitchDamping=0.3
                		RollTorqueTurnFactor=700.0
                		RollTorqueStrafeFactor=100.0
                		RollTorqueMax=300.0
                		RollDamping=0.1
                		MaxRandForce=30.0
                		RandForceInterval=0.5
                		StopThreshold=100
                		bShouldCutThrustMaxOnImpact=true
                	End Object
                	SimObj=SimObject
                	Components.Add(SimObject)
                
                	COMOffset=(X=-40,Z=-50.0)
                
                	BaseEyeheight=30
                	Eyeheight=30
                	bRotateCameraUnderVehicle=false
                	CameraLag=0.05
                	LookForwardDist=290.0
                	bLimitCameraZLookingUp=true
                
                	AirSpeed=2000.0
                	GroundSpeed=1600.0
                
                	UprightLiftStrength=30.0
                	UprightTorqueStrength=30.0
                
                	bStayUpright=true
                	StayUprightRollResistAngle=5.0
                	StayUprightPitchResistAngle=5.0
                	StayUprightStiffness=1200
                	StayUprightDamping=20
                	
                	bRollToDesired = true // ## VITAL CODE: enables rolling of the pawn
                	AirSpeed = 380.0 // maximum speed
                	AccelRate = 800.0 // acceleration speed
                
                	SpawnRadius=180.0
                	RespawnTime=45.0
                
                	bOverrideAVRiLLocks=true
                
                	PushForce=50000.0
                	HUDExtent=140.0
                
                	HornIndex=0
                }
                But to no luck, rolling still doesn't work for me, i tried to add GBA_RollLeft and GBA_RollRight consecutively to Q and E buttons and it doesnt work. Spacebar still doesnt make my vehicle move forward and still makes my vehicle lift itself. The C key still makes my vehicle descent. I'm really runnning out of options here >.<

                I just want to use my mouse to make the camera look around the vehicle surroundings, and make the vehicle roll, pitch, and yaw without moving the camera since I'm not moving the mouse yet. Is that possible guys?




                EDIT:

                Rolling and pitching seems to work now. I just changed the values of the rolltorquestrafefactor, rolltorqueturnfactor, and rolltorquemax since my spaceship is quite big and heavy, i thought that i needed more force to make it move just like the thrustforce. I added more rolldamping to make it controllable and not rolling too much.

                This is my vehicle.uc now:

                Code:
                class UTVehicle_SpaceShip extends UTAirVehicle;
                
                /* etc */ 
                
                var float AR_MaxLift, AR_TurnSpeed, AR_Speed, AR_CurrentForward, AR_AddedLiftSpeed, AR_Acceleration;
                
                /* etc */
                
                simulated function AirRaidKinematics(float DeltaTime)
                {
                	local Vector AR_ForceApplication, AR_ForceRotation, AR_ForwardsNormal, AR_UpwardsNormal, AR_SidewardsNormal;
                	local Vector AR_ForceRotationVectX, AR_ForceRotationVectY, AR_ForceRotationVectZ;
                	local float AR_Lift, AR_ForwardSpeed, AR_NewRise;
                
                	// While there is a player in the biplane:
                	if (PlayerController(Controller) != None)
                	{
                		GetAxes(Rotation, AR_ForwardsNormal, AR_SidewardsNormal, AR_UpwardsNormal);
                		
                		// Roll 
                AR_ForceRotationVectX *= 800 * Rise; // PZ_NewRise is between -1 and 1
                
                		// Pitch 
                AR_ForceRotationVectY *= 30 * -PlayerController(Controller).PlayerInput.aMouseY / 100;
                
                		// Yaw
                AR_ForceRotationVectZ *= 30 * PlayerController(Controller).PlayerInput.aMouseX / 100;
                
                		// The magic happens here ---- Forward 
                AR_ForceApplication = AR_ForwardsNormal * Throttle * 6000;
                
                		AR_CurrentForward += AR_Acceleration * Throttle;
                		AR_ForwardSpeed = AR_CurrentForward * 2.2;
                		// AR_ForwardSpeed is not necessarily true - I'd optimally need to use some 
                		// calculation based off Velocity and current forwards direction Vector...
                
                		// Calculate lift for the biplane:
                		AR_Lift = (AR_ForwardSpeed + AR_AddedLiftSpeed) * Abs(Cos(Rotation.Pitch));
                		if (AR_Lift > AR_MaxLift) AR_Lift = AR_MaxLift;
                		
                		// This gives lift upwards relative to its up-axis and push forwards relative to its forward-axis:
                		AR_ForceApplication.X = AR_UpwardsNormal.X * AR_Lift + AR_CurrentForward * AR_ForwardsNormal.X;
                		AR_ForceApplication.Y = AR_UpwardsNormal.Y * AR_Lift + AR_CurrentForward * AR_ForwardsNormal.Y;
                		AR_ForceApplication.Z = AR_UpwardsNormal.Z * AR_Lift + AR_CurrentForward * AR_ForwardsNormal.Z;
                		
                		// Add forces and rotations
                		Mesh.AddForce(AR_ForceApplication);
                		Mesh.AddTorque(AR_ForceRotation);
                
                	}
                	else
                	{
                		AR_CurrentForward = AR_Speed; // Biplane propellor thrust sets to default
                	}
                }
                
                
                simulated function Tick(float DeltaTime)
                {
                	AirRaidKinematics(DeltaTime);
                	Super.Tick(DeltaTime);
                }
                
                /* etc */
                defaultproperties
                {
                
                Begin Object Class=UDKVehicleSimChopper Name=SimObject
                		MaxThrustForce=300000.0
                		MaxReverseForce=20000.0
                		LongDamping=0.1
                		MaxStrafeForce=0.0
                		LatDamping=0.7
                		MaxRiseForce=1000000.0
                		UpDamping=0.0
                		TurnTorqueFactor=700000.0
                		TurnTorqueMax=1000000.0
                		TurnDamping=100
                		MaxYawRate=3.8
                		PitchTorqueFactor=50000.0
                		PitchTorqueMax=100000.0
                		PitchDamping=0.3
                		RollTorqueTurnFactor=50000.0
                		RollTorqueStrafeFactor=1000.0
                		RollTorqueMax=100000.0
                		RollDamping=2
                		MaxRandForce=00.0
                		RandForceInterval=1.5
                		StopThreshold=100
                		bShouldCutThrustMaxOnImpact=true
                        PitchViewCorrelation=9999.0
                        bAllowZThrust=True
                
                	End Object
                	SimObj=SimObject
                	Components.Add(SimObject)
                
                	bAutoLand=true
                	ContrailColorParameterName=ContrailColor
                	bHomingTarget=true
                	bNoZDampingInAir=false
                
                	bReducedFallingCollisionDamage=true
                
                	bCanStrafe=true
                	bCanFly=true
                	bTurnInPlace=true
                	bFollowLookDir=true
                	bDriverHoldsFlag=false
                	bCanCarryFlag=false
                
                	LookForwardDist=100.0
                
                	IconCoords=(U=989,V=24,UL=43,VL=48)
                
                	bEjectPassengersWhenFlipped=false
                	bMustBeUpright=false
                	UpsideDownDamagePerSec=0.0
                
                	bDropDetailWhenDriving=true
                	bFindGroundExit=false
                
                	//@todo: it would be nice if the alternate path code would count being in a VolumePathNode above the intended alternate path
                	bUseAlternatePaths=false
                
                	bJostleWhileDriving=true
                	bFloatWhenDriven=true
                }
                I am really thankful for this thread cause this really helped me a lot. I can see some improvements now because now my vehicle rolls. haha

                It still rolls and pitches as the camera also moves.... can i change these movement and assign it to other keys like the arow buttons? My vehicle does not move forward too. Spacebar still makes my vehicle go up and C still makes it go down. Maybe make the vehicle forward with W, Slowdown or stop by S, yaw by using keys A and D, rolling and pitching movements by using the arrow keys, and camera movements by moving the mouse.

                So now, my vehicle goes up, down, roll, pitch, no yawing ,forward and backward movements yet. Any ideas on how to do this guys? Thanks

                Comment


                  @deguitz06 I'm happy for you.

                  An idea for my problem : I changed my ship 3d mesh but now he can't move.
                  I have a bone and a view socket but no anim set

                  EDIT: It works. Thanks for the code!

                  @deguitz06
                  Nice code. I like your forward/backward system.
                  I would like to use it but i keep the classic input systems.
                  An idea for how to do that with keeping the roll?

                  Comment


                    Originally posted by elhant1 View Post
                    @deguitz06 I'm happy for you.

                    An idea for my problem : I changed my ship 3d mesh but now he can't move.
                    I have a bone and a view socket but no anim set

                    EDIT: It works. Thanks for the code!

                    @deguitz06
                    Nice code. I like your forward/backward system.
                    I would like to use it but i keep the classic input systems.
                    An idea for how to do that with keeping the roll?
                    @elhant1

                    Actually, forward and backward does not work on me when i add pitch and rolling. I think there has to be a way to set those movements separately.


                    My vehicle pitches down when i move forward making a loop. I also would like to change my rolling movement to another key since my vehicle rolls with my mouse movement making it hard to control. I'd like take out those strafing movements with yawing movements to make my vehicle controllable too. So yeah, if anyone has solutions for those please help me >.>

                    Thanks again

                    Comment


                      Maybe you can use the wheel ?

                      For strafing i don't know what is the name of the variable.

                      Comment


                        mouse wheel? i don't know how lol.

                        and which movement do i use with the wheel?

                        Comment


                          I also would like to change my rolling movement to another key since my vehicle rolls with my mouse movement making it hard to control.
                          You can use mouse wheel for rolling.

                          Comment


                            Originally posted by elhant1 View Post
                            You can use mouse wheel for rolling.
                            any code for that? i dont know how to do it...

                            Comment


                              Originally posted by deguitz06 View Post
                              any code for that? i dont know how to do it...
                              http://udn.epicgames.com/Three/KeyBinds.html

                              Comment


                                Currently I'm trying to figure out how to smoothly rotate a spaceship/vehicle.
                                The way to rotate the spaceship/plane that I've posted before is not very UT/UDK like and doesn't allow for bots/AI and auto pilot so I'm trying a different approach.
                                I've started a separate thread, because the discussion proably will be longer.

                                Comment

                                Working...
                                X