Announcement

Collapse
No announcement yet.

Relative Physics Problem

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

  • replied
    thats strange you have to send it from the controller, but if that works, awesome
    thanks
    i always did extend UTVehicle, must be why some of your posts didnt make sence, or didnt apply to my spaceship. i dont need to do anything with gravity too, its like its in 0G anyway.

    Leave a comment:


  • replied
    Sorry, my last post was really short. I was in a hurry.

    To elaborate:

    The rotation in UDK is done differently than applying the mouse input directly as force/torque to a ship. The rotation (the direction the player should face) is calculated by mouse movement, gamepad and others. The Controller gets a rotation and passes it to the pawn (a human model, a vehicle, etc. Something the player can move).

    Usually we would be able to use this rotation. The problem is that the rotation does not care about roll. On top of that Pitch/Tilt is treated like an unloved stepchild, because only the camera and the weapon orientation need it.

    This is why I wrote my own function SetInputs2, belonging to the ship, that passes the mouse input from the Controller to the ship directly. The ship rotation in the level is then used to set the rotation of controller so the radar is correctly orientated as well. Somewhat of a hack, but it works well.

    If you are familiar with the basics of multiplayer programming in UDK you can use SetInputs2 to send the input accross the network. But this is another topic, consider this just a hint for later. ;-)

    So what needs to be done, to get this to work, like I am currently doing it?

    You need your own game mode class, preferably deriving it from UTGame or UTDeathMatch. This way you can make UDK use your own controller. Most advanced coders will have done that already.

    Now to concrete code:

    The ship, called SpaceShip

    Code:
    Class SpaceShip extends UTVehicle;
    
    var vector input_turn;
    
    ...
    
    // own InputSet function, currently not used
    simulated function SetInputs2(float Yawing, float Pitching, float Rolling)
    {
    	input_turn.X = Rolling; // roll
    	input_turn.Y = Pitching; // pitch / tilt
    	input_turn.Z = Yawing; // yaw
    }
    
    simulated function AirRaidKinematics(float DeltaTime)
    {
          ...
    		// Roll
    		AR_ForceRotationVectX *= input_turn.X;
    
    		// Pitch
    		AR_ForceRotationVectY *= input_turn.Y;
    
    		// Yaw
    		AR_ForceRotationVectZ *= input_turn.Z;
    
    		// Add them together to get final global rotation vector:
    		AR_ForceRotation = AR_ForceRotationVectX + AR_ForceRotationVectY + AR_ForceRotationVectZ;
    }
    
    ...
    The controller, MyControllerPlayer

    Code:
    MyControllerPlayer extends UTPlayerController;
    
    // PlayerTick is only called if the PlayerController has a PlayerInput object. Therefore we need a dummy one
    event PlayerTick (float DeltaTime)
    {
           local SpaceShip ship;
    
    	super.PlayerTick(DeltaTime);
    
          ship = SpaceShip(pawn);
    
         // we are controlling a ship
         if(ship != none)
         {
                Ship.SetInputs2(PlayerInput.aMouseX / 20, -PlayerInput.aMouseY / 20, 0);
                // instead of 0 pass the value of the buttons you want use for roll
         }
    }
    
    // set the rotation of controller to that of the ship
    function ProcessViewRotation( float DeltaTime, out Rotator out_ViewRotation, Rotator DeltaRot )
    {
    	local SpaceShip Ship;
    	local Vector vec; // dummy var to satisfy GetSocketWorldLocation...
    
    	Ship = SpaceShip(Pawn);
    
    	if(Ship == none)
    		super.ProcessViewRotation( DeltaTime, out_ViewRotation, DeltaRot );
    	else
    	{
    		//get the location and rotation of the socket
    		Pawn.Mesh.GetSocketWorldLocationAndRotation(Ship.Seats[0].CameraTag, vec, out_ViewRotation);
    	}
    }
    
    DefaultProperties
    {
    }
    Code:
    // just a dummy, can serve as a central palce for exec functions
    class MyPlayerInput extends UTPlayerInput within MyControllerPlayer;
    
    exec function do Sth()
    {
    
    }
    
    DefaultProperties
    {
    }
    That's it, happy coding guys.

    ----------------------------------------------

    Important news:

    To get gravity for your plane/spaceship is really simple. I just figured it out. Extend from UTVehicle instead of UTAirVehicle.
    Then it won't use PHYS_FYLING anymore. Keep in mind that your vehicle must have a strong enough climbing force to get off the ground if you have the default gravity of -512.

    This seems somewhat strange, but makes sense as UTAirVehicle is supposed to implement a flying vehicle for a FPS, not a flight simulator.

    In conclusion we got a car which can fly. And has no wheels. ;-)
    Attached Files

    Leave a comment:


  • replied
    Interestingly I have the same problem as I am building the ship from scratch again to find some bugs.

    In my working code I have a custom PlayerInput class which does nothing related to the mouse.^^

    My Controller class passes the aMouseX and Y to the ship every tick.

    Code:
    Ship.SetInputs2(PlayerInput.aMouseX / 20, -PlayerInput.aMouseY / 20);
    You have to tweak the 20s of course.

    I'll post here when I found out whether there is an easier way and if the mouse input depends on other things, too.

    Leave a comment:


  • replied
    so how do you get the mouse input in this?
    PlayerController(Controller).PlayerInput.aMouseY always = 0
    same with aStraffe and everything

    single or multiplayer i dont mind

    Leave a comment:


  • replied
    Today I fixed bug in the spaceship movement that has been bugging me for months.

    When the ship is standing completely still in zero gravity (real GravityZ = 0, not -0.000001 or something) it would start to move downwards after some minutes. Downwards in the global sense.

    The reason?

    Code:
    bFloatWhenDriven=true
    in UTAirVehicle.

    bFloatWhenDriven - If true, the vehicle will use a gravity Z-value of -0.1 to simulate floating. Useful for flying vehicles.
    This makes sense for planes and helicopters, but not for spaceships. So add
    Code:
    bFloatWhenDriven=false
    to the defaultproperties of your ship class you fix this issue.

    More about the properties of the vehicle classes:
    http://udn.epicgames.com/Three/Vehic...UDKVehicleBase

    Leave a comment:


  • replied
    While coding the plane for a buddy, I encountered the problem, GentlemanGraphics encountered (spinning, no response to input).

    I forgot to added the lines

    Code:
    	DrivingPhysicalMaterial=PhysicalMaterial'VH_Cicada.materials.physmat_Cicada_driving'
    	DefaultPhysicalMaterial=PhysicalMaterial'VH_Cicada.materials.physmat_Cicada'
    to the default properties.

    This is the same issue koningStoma, btw. It are always the small things bug you the most^^

    Leave a comment:


  • replied
    @koningStoma: You're welcome.

    @tegleg: In my last about 8 vids on youtube I calculate the counter force/torque to slowly stop rotation. ^^ The reason why I abandoned the physMat is that I aim for a somewhat hardcore simulation approach ;-) And I can use it later for stuff like auto pilot and AI. But in most cases the PhysMat will do a better job.

    Leave a comment:


  • replied
    Originally posted by Hiredicespecter View Post
    The 'air friction' your are looking for is called damping. It is NOT set in the script, it is set in the vehicles PhysicalMaterial and called AngularDamping (for turning) and linear damping (for movement).
    I guess you have not assigned any to your vehicle. It needs to PhysMats btw. One when its driving and one when it's not driven. Have a look at the cicada content code.
    Ah, thanks.

    Leave a comment:


  • replied
    ive been experimenting with a solution for that but nothing concrete yet.
    you can work out the rotation rate and add an opposing rotation force, but its jerky and i would like it to self level.
    tried adding a SimHelicopter object, this makes it self level sometimes and others it will spin wildly out of controll.
    still working on it now and then so ill have a solution sooner or later.
    feel free to help anyone?

    edit:
    ninjad by Hiredicespecter
    set it in the phys material eh, ill give that a go thanks

    Leave a comment:


  • replied
    The 'air friction' your are looking for is called damping. It is NOT set in the script, it is set in the vehicles PhysicalMaterial and called AngularDamping (for turning) and linear damping (for movement).
    I guess you have not assigned any to your vehicle. It needs to PhysMats btw. One when its driving and one when it's not driven. Have a look at the cicada content code.

    Leave a comment:


  • replied
    I have been playing around with this stuff and I have come across one problem. My vehicle does not slow down, or stop spinning, once I have applied torque or force.

    Is there any kind of friction functionality present in the existing code? I haven't been able to find it.

    Leave a comment:


  • replied
    Bugf ix for gravity calculation

    The calculation of gravity that I provided some pages ago is wrong for at least two reasons. First, it doesn't consider the vehicle's mass. Just remember what we all hopefully learned in school: F = m * g
    g = self.PhysicsVolume.GetGravityZ()
    m = self.Mesh.BodyInstance.GetBodyMass()

    Second, there is no need to multiply with CustomGravityScaling, it is already included in GetGravityZ().

    I have included the 0.01 factor, because the resulting gravity was too strong and I assume some constant factor is used natively as well. Maybe you have to experiment with that factor.

    New:
    Code:
    if(bDriving)
    {
        AR_ForceApplication.Z += self.PhysicsVolume.GetGravityZ() * self.Mesh.BodyInstance.GetBodyMass() * 0.01;
    }
    Old:
    Code:
    if(bDriving)
    {
        AR_ForceApplication.Z += self.PhysicsVolume.GetGravityZ() * CustomGravityScaling;
    }
    I have edited the original post to refelcted this.

    Leave a comment:


  • replied
    For the xbox-controller issue: the key bindings are handeld in DefaultInput.ini. This file is responsible for assigning any kind fo action to keys. A general introduction can be found here: http://udn.epicgames.com/Three/KeyBinds.html
    For the xbox specific binds search for the line that starts with .Bindings=(Name="XboxTypeS_LeftShoulder"

    I can't help you with UTSekl_Controls, since I haven't used them so far.

    Because of exams and moving, i haven't had time to implement a plane with air lift and stall. This will take some more time.

    Feel free to post any code that can simulate air lift and stall, if you get it working.

    Leave a comment:


  • replied
    Thank you all for a great thread, I've learned a ton reading and experimenting based on the various responses over the past couple months. I quickly got something up and running at first, for a non scriptor, I hope that says something. The above code that Hiredicespecter included for more realistic movement really helped me out a lot. I did have one question though. I'm using an Xbox controller for all of my movement and the controls finally feel right, except that I'd like to bind acceleration to say the left trigger so I can slow down and speed up while leaving Pitch and Roll as they are. How would I go about doing this?

    As a side note, I've been experimenting with UTSkel_Controls for the flaps and rudders and pretty close to getting something that looks halfway decent, though I need to research more on linking these constraints directly to the controller values to respond faster when turning.

    Thanks in advance, great community.

    Leave a comment:


  • replied
    Since I want to code a plane like vehicle within the next few weeks, I had a look at how gravity for flying vehicles works in UDK for starters.

    First of all, why is the space ship, whose code I posted previously, not affected by gravity?

    Because it is using PHYS_FLYING while being driven. Objects in the physic state PHYS_FLYING are no affected by gravity.
    If you exit the space ship, its physic state changes to PHYS_FALLING, in which the ship is affected by gravity and CustomGravityScaling.

    For a plane to be affected by gravity, you could try to use PHYS_FALLING all the time, but this would involve some heavy modification of the vehicle code or might be even impossible without access to native code.
    And since PHYS_FLYING is intended for flying vehicles it is better to stick with it and just add add gravity manually while the space ship/plane is being driven.

    To get the gravity of the gravityVolume the vehicle is currently into (or the world's gravity if it isn't within one):

    Code:
     
    if(bDriving)
    {
        AR_ForceApplication.Z += self.PhysicsVolume.GetGravityZ() * CustomGravityScaling;
    }
    By the way, this behavior makes sense for a game like UT where you wouldn't want something like a plane which needs gravity, lift, drag and thrust. UT just wants some choppers and hovering vehicles.
    This would cover gravity, thrust (the force of the engine) is already covered. I have found the related formulars at wikipedia, but I haven't had the time to test them in UDK yet.

    This side provides an easy explanation of the forces affecting a plane: http://www.aviastar.org/theory/basic...ght/index.html

    Edit

    The calculation of gravity that I provided above is wrong for at least two reasons. First, it doesn't consider the vehicle's mass. Just remember what we all hopefully learned in school: F = m * g
    g = self.PhysicsVolume.GetGravityZ()
    m = self.Mesh.BodyInstance.GetBodyMass()

    Second, there is no need to multiply with CustomGravityScaling, it is already included in GetGravityZ().

    I have included the 0.01, because the resulting gravity was too strong and I assume some constant factor is used natively as well. Maybe you have to experiment with that factor.

    Code:
    if(bDriving)
    {
        AR_ForceApplication.Z += self.PhysicsVolume.GetGravityZ() * self.Mesh.BodyInstance.GetBodyMass() * 0.01;
    }
    I ll post this in an extra post so that the subscribers to this will get a notice of this too.

    Leave a comment:

Working...
X