Announcement

Collapse
No announcement yet.

Relative Physics Problem

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

    #16
    Originally posted by KongWeezY View Post
    where is the AR_AircraftContent and AR_AircraftFactory code... can not get this to work...
    Your Factory and Content scripts should extend the ones I said, and the content is trivial, merely telling UDK what models you're going to be using. You would be best to write your own, but here's an example:
    Code:
    class AR_AircraftFactory extends UTVehicleFactory placeable;
    
    defaultproperties
    {
    	Begin Object Name=SVehicleMesh
    		SkeletalMesh=SkeletalMesh'AR_Content.AR_Biplane'
    		Translation=(X=-40.0,Y=0.0,Z=-70.0)
    	End Object
    
    
    	Begin Object Name=CollisionCylinder
    		CollisionHeight=+120.0
    		CollisionRadius=+200.0
    		Translation=(X=0.0,Y=0.0,Z=-40.0)
    	End Object
    
    	VehicleClassPath="AirRaid.AR_AircraftContent"
    	DrawScale=1
    }

    Comment


      #17
      Syhon, I have to thank you. Your post helped me to make my spaceship move. After a couple of weeks I ended up with this: http://www.youtube.com/watch?v=FdkKXo5b09U.
      For more details have a look at my Work in Progress thread, it's linked to in my sig.

      Comment


        #18
        I have the code working and my airplane yaws, pitches and rotates but it does not move as in I cannot control it. I want to go foward then turn left then come into land can't do it because it is just acting like a helicopter up/down, yaw and pitch but it has no speed so I can't go forward or any other direction I can only face in different directions and it does move slightly on it own but without my control so it will just float away.

        Please help. Thanks.

        Comment


          #19
          @GentlemenGraphics: Could you post your code and a video showing the described behavior on youtube or the like? Otherwise it is nearly impossible to figure out your problem.

          Comment


            #20
            Ok here's the three code files for the airplane:

            AR_Aircraft.uc

            class AR_Aircraft 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);

            // It's probably unnecessary to normalise these:
            AR_ForceRotationVectX = Normal(AR_ForwardsNormal);
            AR_ForceRotationVectY = Normal(AR_SidewardsNormal);
            AR_ForceRotationVectZ = Normal(AR_UpwardsNormal);

            // Rise is NOT between -1 and 1, like it said it was
            AR_NewRise = 0;
            if (Rise != 0) AR_NewRise = Rise / Abs(Rise); // Avoid divide by 0

            // Calculate the XYZ components of the relative steering:
            // Generic controls Steering, Throttle and Rise are set by the controller

            // Roll
            AR_ForceRotationVectX.X *= 35 * -AR_NewRise; // Steering is between -1 and 1
            AR_ForceRotationVectX.Y *= 35 * -AR_NewRise; // Steering is between -1 and 1
            AR_ForceRotationVectX.Z *= 35 * -AR_NewRise; // Steering is between -1 and 1

            // Pitch
            AR_ForceRotationVectY.X *= 30 * Throttle; // Throttle is between -1 and 1
            AR_ForceRotationVectY.Y *= 30 * Throttle; // Throttle is between -1 and 1
            AR_ForceRotationVectY.Z *= 30 * Throttle; // Throttle is between -1 and 1

            // Yaw
            AR_ForceRotationVectZ.X *= 25 * -Steering; // AR_NewRise is between -1 and 1
            AR_ForceRotationVectZ.Y *= 25 * -Steering; // AR_NewRise is between -1 and 1
            AR_ForceRotationVectZ.Z *= 25 * -Steering; // AR_NewRise is between -1 and 1

            // Add them together to get final global rotation vector:
            AR_ForceRotation.X = AR_ForceRotationVectX.X + AR_ForceRotationVectY.X + AR_ForceRotationVectZ.X;
            AR_ForceRotation.Y = AR_ForceRotationVectX.Y + AR_ForceRotationVectY.Y + AR_ForceRotationVectZ.Y;
            AR_ForceRotation.Z = AR_ForceRotationVectX.Z + AR_ForceRotationVectY.Z + AR_ForceRotationVectZ.Z;

            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 */

            UTVehicle_AR_Aircraft_Content.uc

            class UTVehicle_AR_Aircraft_Content extends AR_Aircraft;

            defaultproperties
            {
            Begin Object Name=CollisionCylinder
            CollisionHeight=+70.0
            CollisionRadius=+240.0
            Translation=(X=-40.0,Y=0.0,Z=40.0)
            End Object

            Begin Object Name=SVehicleMesh
            SkeletalMesh=SkeletalMesh'VH_Cicada.Mesh.SK_VH_Cic ada'
            AnimTreeTemplate=AnimTree'VH_Cicada.Anims.AT_VH_Ci cada'
            PhysicsAsset=PhysicsAsset'VH_Cicada.Mesh.SK_VH_Cic ada_Physics'
            AnimSets.Add(AnimSet'VH_Cicada.Anims.VH_Cicada_Ani ms')
            End Object

            DrawScale=1.3

            Health=500
            BigExplosionTemplates[0]=(Template=ParticleSystem'Envy_Effects.VH_Deaths.P _VH_Death_SMALL_Far',MinDistance=350)
            BigExplosionTemplates[1]=(Template=ParticleSystem'Envy_Effects.VH_Deaths.P _VH_Death_SMALL_Near')
            BigExplosionSocket=VH_Death

            Seats.Empty
            Seats(0)={( GunClass=class'UTVWeap_CicadaMissileLauncher',
            GunSocket=(Gun_Socket_02,Gun_Socket_01),
            CameraTag=ViewSocket,
            TurretControls=(LauncherA,LauncherB),
            CameraOffset=-400,
            CameraBaseOffset=(Z=25.0),
            SeatIconPos=(X=0.48,Y=0.25),
            GunPivotPoints=(Main),
            WeaponEffects=((SocketName=Gun_Socket_01,Offset=(X =-80),Scale3D=(X=12.0,Y=15.0,Z=15.0)),(SocketName=Gu n_Socket_02,Offset=(X=-80),Scale3D=(X=12.0,Y=15.0,Z=15.0)))
            )}

            Seats(1)={( GunClass=class'UTVWeap_CicadaTurret',
            GunSocket=(Turret_Gun_Socket_01,Turret_Gun_Socket_ 02,Turret_Gun_Socket_03,Turret_Gun_Socket_04),
            TurretVarPrefix="Turret",
            TurretControls=(Turret_Rotate),
            CameraTag=Turret_ViewSocket,
            CameraOffset=0,
            GunPivotPoints=(MainTurret_Pitch),
            CameraEyeHeight=0,
            SeatIconPos=(X=0.48,Y=0.56),
            ViewPitchMin=-14000.0,
            ViewPitchMax=1.0,
            WeaponEffects=((SocketName=Turret_Gun_Socket_04,Of fset=(X=-80),Scale3D=(X=8.0,Y=10.0,Z=10.0)),(SocketName=Tur ret_Gun_Socket_03,Offset=(X=-80),Scale3D=(X=8.0,Y=10.0,Z=10.0)))
            )}




            VehicleEffects.Empty

            VehicleEffects(0)=(EffectStartTag=TurretWeapon00,E ffectEndTag=STOP_TurretWeapon00,EffectTemplate=Par ticleSystem'VH_Cicada.Effects.P_VH_Cicada_2ndAltFl ash',EffectSocket=Turret_Gun_Socket_01)
            VehicleEffects(1)=(EffectStartTag=TurretWeapon01,E ffectEndTag=STOP_TurretWeapon01,EffectTemplate=Par ticleSystem'VH_Cicada.Effects.P_VH_Cicada_2ndAltFl ash',EffectSocket=Turret_Gun_Socket_02)
            VehicleEffects(2)=(EffectStartTag=TurretWeapon02,E ffectEndTag=STOP_TurretWeapon02,EffectTemplate=Par ticleSystem'VH_Cicada.Effects.P_VH_Cicada_2ndAltFl ash',EffectSocket=Turret_Gun_Socket_03)
            VehicleEffects(3)=(EffectStartTag=TurretWeapon03,E ffectEndTag=STOP_TurretWeapon03,EffectTemplate=Par ticleSystem'VH_Cicada.Effects.P_VH_Cicada_2ndAltFl ash',EffectSocket=Turret_Gun_Socket_04)

            VehicleEffects(4)=(EffectStartTag=EngineStart,Effe ctEndTag=EngineStop,EffectTemplate=ParticleSystem' VH_Cicada.Effects.P_VH_Cicada_GroundEffect',Effect Socket=GroundEffectBase)
            VehicleEffects(5)=(EffectStartTag=EngineStart,Effe ctEndTag=EngineStop,EffectTemplate=ParticleSystem' VH_Cicada.Effects.P_VH_Cicada_Exhaust',EffectSocke t=LeftExhaust)
            VehicleEffects(6)=(EffectStartTag=EngineStart,Effe ctEndTag=EngineStop,EffectTemplate=ParticleSystem' VH_Cicada.Effects.P_VH_Cicada_Exhaust',EffectSocke t=RightExhaust)
            VehicleEffects(7)=(EffectStartTag=DamageSmoke,Effe ctEndTag=NoDamageSmoke,bRestartRunning=false,Effec tTemplate=ParticleSystem'Envy_Effects.Vehicle_Dama ge.P_Vehicle_Damage_1_Cicada',EffectSocket=DamageS moke_01)

            VehicleAnims(0)=(AnimTag=Created,AnimSeqs=(InActiv eStill),AnimRate=1.0,bAnimLoopLastSeq=false,AnimPl ayerName=CicadaPlayer)
            VehicleAnims(1)=(AnimTag=EngineStart,AnimSeqs=(Get In),AnimRate=1.0,bAnimLoopLastSeq=false,AnimPlayer Name=CicadaPlayer)
            VehicleAnims(2)=(AnimTag=Idle,AnimSeqs=(Idle),Anim Rate=1.0,bAnimLoopLastSeq=true,AnimPlayerName=Cica daPlayer)
            VehicleAnims(3)=(AnimTag=EngineStop,AnimSeqs=(GetO ut),AnimRate=1.0,bAnimLoopLastSeq=false,AnimPlayer Name=CicadaPlayer)


            ContrailEffectIndices=(2,3,4,5,13,14)
            GroundEffectIndices=(10)

            // Sounds
            // Engine sound.
            Begin Object Class=AudioComponent Name=RaptorEngineSound
            SoundCue=SoundCue'A_Vehicle_Cicada.SoundCues.A_Veh icle_Cicada_EngineLoop'
            End Object
            EngineSound=RaptorEngineSound
            Components.Add(RaptorEngineSound);

            CollisionSound=SoundCue'A_Vehicle_Cicada.SoundCues .A_Vehicle_Cicada_Collide'
            EnterVehicleSound=SoundCue'A_Vehicle_Cicada.SoundC ues.A_Vehicle_Cicada_Start'
            ExitVehicleSound=SoundCue'A_Vehicle_Cicada.SoundCu es.A_Vehicle_Cicada_Stop'

            // Scrape sound.
            Begin Object Class=AudioComponent Name=BaseScrapeSound
            SoundCue=SoundCue'A_Gameplay.A_Gameplay_Onslaught_ MetalScrape01Cue'
            End Object
            ScrapeSound=BaseScrapeSound
            Components.Add(BaseScrapeSound);

            // Initialize sound parameters.
            EngineStartOffsetSecs=2.0
            EngineStopOffsetSecs=1.0

            IconCoords=(U=988,V=0,UL=33,VL=42)

            ExplosionSound=SoundCue'A_Vehicle_Cicada.SoundCues .A_Vehicle_Cicada_Explode'



            PassengerTeamBeaconOffset=(X=-125.0f,Y=0.0f,Z=-105.0f);
            ReferenceMovementMesh=StaticMesh'Envy_Effects.Mesh .S_Air_Wind_Ball'

            HudCoords=(U=106,V=125,UL=-106,VL=124)
            TeamMaterials[0]=MaterialInstanceConstant'VH_Cicada.Materials.MI_V H_Cicada_Red'
            TeamMaterials[1]=MaterialInstanceConstant'VH_Cicada.Materials.MI_V H_Cicada_Blue'

            BurnOutMaterial[0]=MaterialInterface'VH_Cicada.Materials.MITV_VH_Cic ada_Red_BO'
            BurnOutMaterial[1]=MaterialInterface'VH_Cicada.Materials.MITV_VH_Cic ada_Blue_BO'

            SpawnMaterialLists[0]=(Materials=(MaterialInterface'VH_Cicada.Materials .MI_VH_Cicada_Spawn_Red'))
            SpawnMaterialLists[1]=(Materials=(MaterialInterface'VH_Cicada.Materials .MI_VH_Cicada_Spawn_Blue'))

            DamageMorphTargets(0)=(InfluenceBone=Lt_Gun_Yaw,Mo rphNodeName=none,Health=150,DamagePropNames=(Damag e2))
            DamageMorphTargets(1)=(InfluenceBone=Rt_Gun_Yaw,Mo rphNodeName=none,Health=150,DamagePropNames=(Damag e2))
            DamageMorphTargets(2)=(InfluenceBone=FrontGuardDam age,MorphNodeName=none,Health=150,DamagePropNames= (Damage1))
            DamageMorphTargets(3)=(InfluenceBone=MainTurret_Ya w,MorphNodeName=none,Health=150,DamagePropNames=(D amage3))

            DamageParamScaleLevels(0)=(DamageParamName=Damage1 ,Scale=3)
            DamageParamScaleLevels(1)=(DamageParamName=Damage2 ,Scale=1.5)
            DamageParamScaleLevels(2)=(DamageParamName=Damage3 ,Scale=2.5)

            DrivingPhysicalMaterial=PhysicalMaterial'VH_Cicada .materials.physmat_Cicada_driving'
            DefaultPhysicalMaterial=PhysicalMaterial'VH_Cicada .materials.physmat_Cicada'

            bHasEnemyVehicleSound=true
            EnemyVehicleSound(0)=SoundNodeWave'A_Character_IGM ale.BotStatus.A_BotStatus_IGMale_EnemyCicada'
            }

            UTVehicleFactory_AR_Aicraft.uc

            class UTVehicleFactory_AR_Aicraft extends UTVehicleFactory placeable;

            defaultproperties
            {
            Begin Object Name=SVehicleMesh
            SkeletalMesh=SkeletalMesh'VH_Cicada.Mesh.SK_VH_Cic ada'
            Translation=(X=-40.0,Y=0.0,Z=-70.0)
            End Object


            Begin Object Name=CollisionCylinder
            CollisionHeight=+120.0
            CollisionRadius=+200.0
            Translation=(X=0.0,Y=0.0,Z=-40.0)
            End Object

            VehicleClassPath="UTGameContent.UTVehicle_AR_Aircr aft_Content"
            DrawScale=1

            }

            Thats the code. Please help me it's really important.

            Thanks.

            Comment


              #21
              The code above acts more like a hovering helicopter then a plane please help me fix it.

              Comment


                #22
                Please use code tags to post code, it makes it better to read.
                Code:
                 [codea] insert your code here [/codea] without the a^^
                UTVehicleFactory_AR_Aicraft.uc and UTVehicle_AR_Aircraft_Content.uc are fine.

                Please tell me how familiar you are with vector math, programming and movement related physics. This way I know how much I need to explain.

                For testing purposes you should place your plane in a (big) GravityVolume with a gravity of 0. This will make it easier to see what your code does, because damping, friction and especially gravity will make your life difficult in the beginning.


                The function AirRaidKinematics needs to be fixed, because Syhon hasn't been right about the way forces work on a plane.

                I will try to show you how a simple spaceship is done, since it is way easier and I don't want to write your plane myself. ;-)

                Code:
                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_NewRise;
                
                // While there is a player in the biplane:
                if (PlayerController(Controller) != None)
                {
                GetAxes(Rotation, AR_ForwardsNormal, AR_SidewardsNormal, AR_UpwardsNormal);
                
                // It's probably unnecessary to normalise these:
                AR_ForceRotationVectX = Normal(AR_ForwardsNormal);
                AR_ForceRotationVectY = Normal(AR_SidewardsNormal);
                AR_ForceRotationVectZ = Normal(AR_UpwardsNormal);
                
                // Rise is NOT between -1 and 1, like it said it was
                AR_NewRise = 0;
                if (Rise != 0) AR_NewRise = Rise / Abs(Rise); // Avoid divide by 0
                
                // Calculate the XYZ components of the relative steering:
                // Generic controls Steering, Throttle and Rise are set by the controller
                
                // Roll
                // No rolling for now, I will use q and e for the forward movement for the time being
                // AR_ForceRotationVectX *= 35 * -AR_NewRise; // AR_NewRise is between -1 and 1
                
                // Pitch
                AR_ForceRotationVectY *= 30 * Throttle; // Throttle is between -1 and 1
                
                // Yaw
                AR_ForceRotationVectZ *= 25 * -Steering; // Steering is between -1 and 1
                
                // Add them together to get final global rotation vector:
                AR_ForceRotation = AR_ForceRotationVectX + AR_ForceRotationVectY + AR_ForceRotationVectZ;
                
                // The magic happens here
                AR_ForceApplication = AR_UpwardsNormal * 0 + 5 * AR_NewRise * AR_ForwardsNormal;
                
                // Add forces and rotations
                Mesh.AddForce(AR_ForceApplication);
                Mesh.AddTorque(AR_ForceRotation);
                }
                else
                {
                // if nobody is in the plane, don't apply forces to it, do nothing
                }
                }
                Although I haven't tested it, it should work.

                [EDIT] I tested it now, and it works.

                Now for a short explanation of what I did.

                The replacement of lines like:
                Code:
                AR_ForceRotationVectX.X *= 35 * -AR_NewRise; // Steering is between -1 and 1
                AR_ForceRotationVectX.Y *= 35 * -AR_NewRise; // Steering is between -1 and 1
                AR_ForceRotationVectX.Z *= 35 * -AR_NewRise; // Steering is between -1 and 1
                with
                Code:
                AR_ForceRotationVectX *= 35 * -AR_NewRise; // Steering is between -1 and 1
                is simply an improvement to make the code more readable.

                I commented
                Code:
                 // AR_ForceRotationVectX *= 35 * -AR_NewRise; // AR_NewRise is between -1 and 1
                because I want to use Q and E (if you have adopted Syphon's bindings) or the default Jump and Crouch buttons for forward movement. As a consquence the plane won't be able to roll.
                No complains please, this is just a quick and dirty version. I would never use such keyboard layout for a plane if I were serious.

                The magic happens here:
                Code:
                // The magic happens here
                AR_ForceApplication = AR_UpwardsNormal * 0 + 5 * AR_NewRise * AR_ForwardsNormal;
                I use the input variable AR_NewRise to calculate the forward movement. Yeah I know, the name AR_NewRise doesn't fit anymore.

                If you are unfamiliar with vector math you must learn it. No way around it.

                Now you should have a vehicle that can turn left/right & up/down and move forward/backward.

                And now I am done with this post, it took me long enough.^^

                Comment


                  #23
                  Thank you for your much needed help : ) but I am still running into problems to aid you with this problem I have uploaded a video showing the aircraft and how it handles.

                  I hope we can get this fixed. Thanks.

                  http://www.youtube.com/watch?v=qiEh4cMcIUg

                  Comment


                    #24
                    I still need your help someone please.

                    Comment


                      #25
                      Here's a video showing the handling of the aircraft. It handles like a balloon which I have no control over because seriously it just goes up and thats it.



                      http://www.youtube.com/watch?v=qiEh4cMcIUg

                      Help please.

                      Thanks.

                      Comment


                        #26
                        Anyone please help.

                        Comment


                          #27
                          I found the mistake, change the line
                          Code:
                           // The magic happens here
                          AR_ForceApplication = AR_UpwardsNormal * 0 + AR_NewRise * AR_ForwardsNormal;
                          to
                          Code:
                           // The magic happens here
                          AR_ForceApplication = AR_UpwardsNormal * 0 + 5 * AR_NewRise * AR_ForwardsNormal;
                          I underestimated the force needed to move the Cicada. So you just need to multipy it by 5 to get a decent result.
                          I have corrected the mistake in the previously posted code, too.

                          This will give you a simple spaceship/plane/whatsoever.

                          Things that you still need to do:
                          -Write your own vehicle camera code, a good tutorial is here: http://forums.epicgames.com/threads/...ehicle-Cameras
                          -Make the input/movement more plane like, something similar to hawx would be easy: Roll with A/D (steering), Pitch with W/S (Throttle), Forward/backward: Space/C (AR_NewRise) and a default forward speed

                          Consider these your homework^^

                          Comment


                            #28
                            It still doesn't work. Acts exactly the same the as before.

                            Comment


                              #29
                              What keys did you press and what key bindings do you use? The default udk (space and C) ones or the ones proposed by Syphon (q and e)?
                              If key binding is not the issue here, replace
                              Code:
                                // The magic happens here
                              AR_ForceApplication = AR_UpwardsNormal * 0 + 5 * AR_NewRise * AR_ForwardsNormal;
                              with
                              Code:
                                // The magic happens here
                              AR_ForceApplication = AR_UpwardsNormal * 0 + 5 * AR_ForwardsNormal;
                              This should make the Cicada move forward without any player input as long as you are in it.
                              Another reason might gravity. Is your Cicada placed in a large GravityVolume with Gravity set to 0?

                              These are the only reasons I can think of, because I used the code you posted before and posted exactly the code I used.

                              Comment


                                #30
                                Just a minor observation, but AR_UpwardsNormal * 0 is redundant and can be removed.

                                Comment

                                Working...
                                X