Page 1 of 6 123 ... LastLast
Results 1 to 10 of 52

Thread: Inside the Scorpion - Scripting your own vehicles

  1. #1
    tegleg
    Guest

    Inside the Scorpion - Scripting your own vehicles

    hello

    This is a ruff insight to the script side of making a vehicle.

    Lorenz si è gentilmente offerto di tradurre questo tutorial in italiano!
    Lorenz is kindly translating this into italian find it here

    To try and keep the document length down here we will use UTVehicle_Scorpion as a 'template' for our own car.
    The same can be done with Cicada and Manta for flying and hovering vehicles.
    Epics vehicle pages are here.
    http://udn.epicgames.com/Three/SettingUpVehicles.html
    http://udn.epicgames.com/Three/Vehic...icalGuide.html
    this ones for mobile cars including a downloadable example.
    http://udn.epicgames.com/Three/Mobil...leExample.html

    im going to try and write here as complete a guide as a can be bothered with,
    i was going to do it more advanced than this but its already a monster post.
    get ready here it comes

    Step 1. The script files. (Below)
    Step 2. Modify your cars appearance.
    Step 3. Modify your cars performance.
    Common problems and solutions.

    Before you start!

    if you havnt already got your own project folder make one now. if you have, skip to Step 1.
    more info on starting your own script project can be found here. http://udn.epicgames.com/Three/Devel...ptProject.html

    navigate to UDK/Development/Src/
    make a new folder, call it what you want but here ill call it 'TegIsAce'.
    make another new folder inside that and call it 'Classes'
    now you have something like this
    UDK/Development/Src/TegIsAce/Classes
    this is where all your custom script files will live.

    to make the engine know about your project we need to tell it.
    open UDK/UDKGame/Config
    find DefaultEngine.ini and double click to open it.

    find this bit
    Code:
    [UnrealEd.EditorEngine]
    +EditPackages=UTGame
    +EditPackages=UTGameContent
    add the name of your new script folder here like this
    Code:
    [UnrealEd.EditorEngine]
    +EditPackages=UTGame
    +EditPackages=UTGameContent
    +EditPackages=TegIsAce
    if you try and start udk now it will moan at you because the script folder is empty. so lets get adding stuff.

    Step 1.

    we will start by making a copy of the scorpoin script files.

    look inside
    UDK/Development/Src/UTGame/Classes
    UDK/Development/Src/UTGameContent/Classes
    and copy these files

    UTVehicle_Scorpion
    UTVehicleScorpionWheel
    UTVehicle_Scorpion_Content
    UTVehicleFactory_Scorpion

    into your folder ie UDK/Development/Src/TegIsAce/Classes

    Rename all the files like this

    UTVehicle_MyCar
    UTVehicleMyCarWheel
    UTVehicle_MyCar_Content
    UTVehicleFactory_MyCar

    now you need to open them up and rename the class to match the file name. use any text editor (not word) like WotGreal or Context

    open the file you called UTVehicle_MyCar.uc
    the first line of code declares the class name and the class it extends from.
    it will look like this.
    Code:
    class UTVehicle_Scorpion extends UTVehicle
    change it to the same as the file name like this.
    Code:
    class UTVehicle_MyCar extends UTVehicle
    do the same with the others

    class UTVehicleScorpionWheel extends UDKVehicleWheel;
    to
    class UTVehicleMyCarWheel extends UDKVehicleWheel;

    class UTVehicle_Scorpion_Content extends UTVehicle_Scorpion;
    to
    class UTVehicle_MyCar_Content extends UTVehicle_MyCar;
    *notice this one extends UTVehicle_MyCar;

    class UTVehicleFactory_Scorpion extends UTVehicleFactory;
    to
    class UTVehicleFactory_MyCar extends UTVehicleFactory;
    keep this file open and look to almost the last line of code.

    Code:
    VehicleClassPath="UTGameContent.UTVehicle_Scorpion_Content"
    this needs to be changed to your folder . your car content.
    Code:
    VehicleClassPath="TegIsAce.UTVehicle_MyCar_Content"
    Save Everything Often!

    you now have your own independant version of the scorpion!
    go ahead and recompile the scripts and have a drive around in it. it is an exact copy of the scorpion so nothing too exciting yet.

    in the next parts we will have a look at spicing things up a bit

  2. #2
    tegleg
    Guest
    Step 2.

    Modify your cars appearance.
    if you dont have your own car skelital mesh ready skip this step and watch Geodavs tutorials.

    we need to specify the skelital mesh, physics asset, morph targets and animations that will be used in your car.
    open up UTVehicle_MyCar_Content and find this block of code.
    Code:
    Begin Object Name=SVehicleMesh
    		SkeletalMesh=SkeletalMesh'VH_Scorpion.Mesh.SK_VH_Scorpion_001'
    		AnimTreeTemplate=AnimTree'VH_Scorpion.Anims.AT_VH_Scorpion_001'
    		PhysicsAsset=PhysicsAsset'VH_Scorpion.Mesh.SK_VH_Scorpion_001_Physics'
    		MorphSets[0]=MorphTargetSet'VH_Scorpion.Mesh.VH_Scorpion_MorphTargets'
    		AnimSets.Add(AnimSet'VH_Scorpion.Anims.K_VH_Scorpion')
    		RBCollideWithChannels=(Default=TRUE,BlockingVolume=TRUE,GameplayPhysics=TRUE,EffectPhysics=TRUE,Vehicle=TRUE,Untitled4=TRUE)
    	End Object
    for the purpose of this tutorial i will just change the mesh and physics asset like this, you might have your own anims and morph targets too.
    Code:
    Begin Object Name=SVehicleMesh
    		SkeletalMesh=SkeletalMesh'MyCar_Package.MyCar_Mesh'
    		AnimTreeTemplate=AnimTree'VH_Scorpion.Anims.AT_VH_Scorpion_001'
    		PhysicsAsset=PhysicsAssetMyCar_Package.MyCar_Physics'
    		MorphSets[0]=MorphTargetSet'VH_Scorpion.Mesh.VH_Scorpion_MorphTargets'
    		AnimSets.Add(AnimSet'VH_Scorpion.Anims.K_VH_Scorpion')
    		RBCollideWithChannels=(Default=TRUE,BlockingVolume=TRUE,GameplayPhysics=TRUE,EffectPhysics=TRUE,Vehicle=TRUE,Untitled4=TRUE)
    	End Object
    the skelital mesh is also referenced inside your vehicle factory.
    a vehicle factory is kind of a vehicle spawner and is not altogether neccesary as we will see later when we tune our car.
    open UTVehicleFactory_MyCar and change the mesh.

    SkeletalMesh=SkeletalMesh'VH_Scorpion.Mesh.SK_VH_S corpion_001'
    to
    SkeletalMesh=SkeletalMesh'MyCar_Package.MyCar_Mesh '

    Changing the Wheels.
    you need to reference your new wheel class in your new car. not the wheel you visually see in the game (thats your model) but the physical representation of the wheels in the game engine (udk).
    open up UTVehicle_Mycar and scroll right down almost to the end to find the wheel objects.
    Code:
    Begin Object Class=UTVehicleScorpionWheel Name=RRWheel
    		BoneName="B_R_Tire"
    		BoneOffset=(X=0.0,Y=20.0,Z=0.0)
    		SkelControlName="B_R_Tire_Cont"
    	End Object
    	Wheels(0)=RRWheel
    
    	Begin Object Class=UTVehicleScorpionWheel Name=LRWheel
    		BoneName="B_L_Tire"
    		BoneOffset=(X=0.0,Y=-20.0,Z=0.0)
    		SkelControlName="B_L_Tire_Cont"
    	End Object
    	Wheels(1)=LRWheel
    
    	Begin Object Class=UTVehicleScorpionWheel Name=RFWheel
    		BoneName="F_R_Tire"
    		BoneOffset=(X=0.0,Y=20.0,Z=0.0)
    		SteerFactor=1.0
    		LongSlipFactor=2.0
    		LatSlipFactor=3.0
    		HandbrakeLongSlipFactor=0.8
    		HandbrakeLatSlipFactor=0.8
    		SkelControlName="F_R_Tire_Cont"
    	End Object
    	Wheels(2)=RFWheel
    
    	Begin Object Class=UTVehicleScorpionWheel Name=LFWheel
    		BoneName="F_L_Tire"
    		BoneOffset=(X=0.0,Y=-20.0,Z=0.0)
    		SteerFactor=1.0
    		LongSlipFactor=2.0
    		LatSlipFactor=3.0
    		HandbrakeLongSlipFactor=0.8
    		HandbrakeLatSlipFactor=0.8
    		SkelControlName="F_L_Tire_Cont"
    	End Object
    	Wheels(3)=LFWheel
    change the Object Class in all 4 wheel objects to your new wheel.
    Code:
    Begin Object Class=UTVehicleMyCarWheel Name=RRWheel
    		BoneName="B_R_Tire"
    		BoneOffset=(X=0.0,Y=20.0,Z=0.0)
    		SkelControlName="B_R_Tire_Cont"
    	End Object
    	Wheels(0)=RRWheel
    ...
    a little extra i always add (dont know if it really makes any difference) is the side of the wheels. Side=SIDE_Right or Side=SIDE_Left.
    add this to all 4 of your wheel objects like this.
    Code:
    Begin Object Class=UTVehicleMyCarWheel Name=RRWheel
    		BoneName="B_R_Tire"
    		BoneOffset=(X=0.0,Y=20.0,Z=0.0)
    		SkelControlName="B_R_Tire_Cont"
                    Side=SIDE_Right
    	End Object
    	Wheels(0)=RRWheel
    
    	Begin Object Class=UTVehicleMyCarWheel Name=LRWheel
    		BoneName="B_L_Tire"
    		BoneOffset=(X=0.0,Y=-20.0,Z=0.0)
    		SkelControlName="B_L_Tire_Cont"
    Side=SIDE_Left
    	End Object
    	Wheels(1)=LRWheel
    ....
    We will sort out the wheel radius when we tune our car next.

  3. #3
    tegleg
    Guest
    Step 3.

    Modify your cars performance.

    **
    A bit about the physics, bear this in mind when you are tuting your car.
    as i suspected the wheels play no part in the physics of the car, instead they are merely a visual representation and forces are applied to the car chassis directly.
    http://http://udn.epicgames.com/Thre...led%20Vehicles
    Wheeled vehicles in Unreal Engine 3 are simulated as a single rigid body. Ray-casts are made from points on the car chassis downwards to see where they hit the ground, and forces are computed at the contact point based on a number of parameters. There are no physical `wheel' objects - the engine just stores how fast each wheel is moving, and uses that in the calculations for forces generated.
    **

    for this step we will make the vehicle 'placeable' so we can play with the cars settings in the editor.

    open UTVehicle_MyCar_Content and add the word placeable like this.
    Code:
    class UTVehicle_MyCar_Content extends UTVehicle_MyCar
    placeable;
    to make your cars physics alive at level start you need to add this line in the PostBeginPlay() function in UTVehicle_MyCar.
    Mesh.WakeRigidBody();
    Code:
    simulated event PostBeginPlay()
    {
       blah stuff here
    ...
        Mesh.WakeRigidBody();
    }
    compile the script and open the editor.
    open the Actor Browser and go down to vehicles. you will now see UTVehicle_MyCar_Content as well as UTVehicleFactory_MyCar.
    drag UTVehicle_MyCar_Content onto your map and double click (or f4) to open its properties.
    here we can change almost every variable involved in the handling of your car. it will not save the changes into your script but serves as a testing platform.

    Wheel Radius.

    the chances are that your car wheels are not the same size as the scorpions, so we will sort that out now.
    with the car properties open in the editor, click on SVehicle and you will see 'Wheels'.
    click the arrow to the left of it to open it further. you will see 0, 1, 2, 3 each with an arrow, these are your 4 wheels.
    open 0, then SVehicle Wheel and you will see all sorts including 'Wheel Radius'.
    change the number on all the wheel objects to make them bigger or smaller so that your car wheels look as if they are on the ground, not floating in the air or sunk into the ground.

    Wheel Slip.
    whilst you have the wheel object properties open lets have a play with the tyre grip. look for Long Slip Factor and Lat Slip Factor.
    Long Slip is forwards grip and Lat Slip is sideways.
    depending on the speed, size and shape of your vehicle this can be anywhere from around 1.0 to 3.0. 1.5 is a good starting point.

    Lat and Long slip scale the slip curve defined in the SimObject, this is where your 'real' grip is defined.
    ie this bit
    Code:
    // Longitudinal tire model based on 10% slip ratio peak
            WheelLongExtremumSlip=0.3
            WheelLongExtremumValue=1.0
            WheelLongAsymptoteSlip=1.0
            WheelLongAsymptoteValue=0.9
    
            // Lateral tire model based on slip angle (radians)
            WheelLatExtremumSlip=0.8     // 20 degrees
            WheelLatExtremumValue=0.9
            WheelLatAsymptoteSlip=0.5    // 80 degrees
            WheelLatAsymptoteValue=1.5
    *note you will probably have to change these values again when we speed the car up.

    once you find the correct wheel radius and good slip factors you can put it in your wheel script. open UTVehicleMyCarWheel and change it there to make it permanent.
    Code:
    class UTVehicleMyCarWheel extends UDKVehicleWheel;
    
    defaultproperties
    {
    	WheelRadius=27
    ...
    LongSlipFactor=2.0
    	LatSlipFactor=2.75
    Speed.
    the main thing holding back the scorpions top speed is a limit that has been set on the physics called 'MaxSpeed'. lets bump that up now.
    open UTVehicle_MyCar and add this line in the DefaultProperties block, put it at the end so you can find it again easily.
    DefaultProperties contains all the goodies we will mess with.
    Code:
    defaultproperties
    {
    blah blah lots of stuff here
    ..
    MaxSpeed=8500
    }
    Gearbox.
    keep UTVehicle_MyCar open.
    the gearbox is defined as an array called TorqueVSpeedCurve.
    you will find it in DefaultProperties inside the SimObject. its full of numbers that need to be changed but ill write words to show you whats going on.
    Code:
    TorqueVSpeedCurve=(Points=((Reverse),(First Gear),(Second),(Third),(Fourth),(Fifth)))
    here is TorqueVSpeedCurve from one of my cars to get you started. not super fast but definately not slow.
    Code:
    TorqueVSpeedCurve=(Points=((InVal=-590.0,OutVal=0.0),(InVal=-100.0,OutVal=28.0),(InVal=0.0,OutVal=55.0),(InVal=450.0,OutVal=60.0),(InVal=6050.0,OutVal=10.0),(InVal=9150.0,OutVal=0.0)))
    you can mess around with these values in the editor.
    in the car properties go down to SVehicle - Sim Obj - UDKVehicle Sim Car
    open TorqueVSpeedCurve - Points
    these are your gears, Inval is speed, OutVal is torque.

    Other Stuff.
    here are some things you might like to change. they can all be found in the Sim Object.

    the scorpion grinds to an abrupt halt as soon as you stop accelerating. to make it more realistic so the car free wheels change this.
    EngineBrakeFactor=0.005

    to give the brakes a more realistic force change this.
    MaxBrakeTorque=25.0

    now that your car goes really fast you will notice you cannot steer at high speeds. change the values in MaxSteerAngleCurve.
    this works for my cars
    Code:
    MaxSteerAngleCurve=(Points=((InVal=0,OutVal=25),(InVal=600.0,OutVal=20.0),(InVal=3100.0,OutVal=16.0),(InVal=4400.0,OutVal=12.0),(InVal=5000.0,OutVal=9.0)))
    also for a quick fix change this.
    MinHardTurnSpeed=99999.0

    to make the vehicle able to hold a drift change this.
    WheelLatAsymptoteSlip=8.4

    these are the most usefull things to change but you now have the freedom to play with almost any setting in the editor.

    by now you should have your own car that goes fast and drifts well
    if not please have a look at the next post.

  4. #4
    tegleg
    Guest
    Common problems and solutions.

    Compile Errors.

    if you get an error warning when you compile READ WHAT IT SAYS. it will give you the class and the line number of the offending error.
    the most frequent error is caused by typos or stray spaces so double check. missing the ';' from the end of a line is another.

    My car doesnt show up in the game.
    make sure the VehicleClassPath is correct in your vehicle factory.
    Code:
    VehicleClassPath="TegIsAce.UTVehicle_MyCar_Content"
    if this doesnt fix it open the unreal FrontEnd and do a script full recompile.

    Wheels spin but no movement / too far up into the body.
    this is usualy a problem in your model. move the wheels down a bit in your 3d modeling prog and re-import.
    another thing that can affect this is WheelSuspensionStiffness in the Sim Oject.
    change WheelSuspensionDamping for 'bouncy' susspension issues.

    My car uses the scorpion materials.
    the scorpion materials are set in the UTVehicle_MyCar_Content. change these to your materials
    Code:
    SpawnMaterialLists[0]=(Materials=(MaterialInterface'VH_Scorpion.Materials.MI_VH_Scorpion_Spawn_Red'))
    	SpawnMaterialLists[1]=(Materials=(MaterialInterface'VH_Scorpion.Materials.MI_VH_Scorpion_Spawn_Blue'))
    
    	TeamMaterials[0]=MaterialInstanceConstant'VH_Scorpion.Materials.MI_VH_Scorpion_Red'
    	TeamMaterials[1]=MaterialInstanceConstant'VH_Scorpion.Materials.MI_VH_Scorpion_Blue'
    My car is the wrong scale.
    change the scale in your modeling prog or in UTVehicle_MyCar_Content.
    DrawScale=1.2

    My car just wheelies.
    another thing that can be fixed in your modeling prog.
    the Main_Root bone needs to be in the exact centre and on the floor of your car.
    the centre of mass can also be changed in UTVehicle_MyCar.
    COMOffset=(x=-40.0,y=0.0,z=-36.0)

    My car points the wrong way / on its side.
    a modeling problem. re-orientate the model and re-import.

    Camera blah...
    http://forums.epicgames.com/showthread.php?t=800741

    My Vehicle only 'falls' to the ground when the player takes control of it
    with UTVehicles the factory initialises the physics.
    if you dont use a factory and place the vehicle instead put this in postbeginplay()
    Code:
    Mesh.WakeRigidBody();
    Wheels Dont Turn
    either:
    animtree not set up properly, take a look at the scorpion's
    wheels not skinned properly, re-skin in the modeling app and re-import

    Let me know if you have a different problem, cant think of any more atm.

  5. #5
    gaz661
    Guest
    as my bike is using the scorpion code i guess this is the best place to ask for advice on the one remaining problem.its quite a fundemental one,but one i thought would be quite easy to fix.



    as you can see,the bike leans the wrong way.obviously its using car suspension so will act like a car.my plan was to reverse the physics on the roll axis.
    the bike is inherently unstable so im using bstayupright=ture and StayUprightRollResistAngle.this is set to 5 in the video till i get it sorted but works well up to a lean angle of 22.and StayUprightPitchResistAngle=25.0 to stop it flipping on wheelies.
    setting the StayUprightRollResistAngle to a negative number didnt work,this is how i achieved a bike sim in max.i went through all the code and didnt find anything that seemed to relate to the problem untill i got all the way to SVehicle.uc where there is the line InertiaTensorMultiplier=(x=1.0,y=1.0,z=1.0) which looked promising but had really bad side effects when using a negative number.

    is it possible to reverse the physics or should i look into faking it in the animtree by rotating the root when the bike is turning?

    thanks.

  6. #6
    skwisdemon666
    Guest
    I would go ahead and try the doing it in anim tree, since you will need to do more stuff like it later, like the handlebars turning.

  7. #7
    tegleg
    Guest
    yes do the handlebars in the animtree

    for leaning change the Z offset in centre of mass
    COMOffset=(x=0.0,y=0.0,z=0.0)

    like
    COMOffset=(x=0.0,y=0.0,z=-10.0)
    or something

  8. #8
    gaz661
    Guest
    nice one tegleg,was beginning to think youd left the planet or something.i new it would be something simple that i had overlooked.

    already had it set at -5,ive now canged it to -45.its working great.just need to mess with the uprighttime and lift strengh to get it a little less wobbly.

  9. #9
    Showster
    Guest
    Hey Gaz661

    Would you mind sharing what your rig looks like for your bike i.e. did you rig just 2 wheels or did you put 4 in there? I've seen multiple solutions for bikes but yours looks to be pretty good!

    Also Tegleg killer write up nice one

    All the best

    Greg

  10. #10
    gaz661
    Guest
    the bike has four wheels.the front and back left wheels are centred to the root,and are the ones used to drive the bike.the front and rear right wheels are offset just a little.there are three zxrwheel.uc files.one to drive the rear left,one to turn the front left and the third sets the wheel radius of the right wheels to 2 so that they dont make contact.i will post the max file this evening for you to check out.


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •