thpsX

- => Create-A- => Topic started by: Xgthug on November 25, 2018, 08:06:52 pm

Title: TUTORIAL: Creating classic rails, rail boosts, etc.
Post by: Xgthug on November 25, 2018, 08:06:52 pm
Hey guys, I thought I'd expand on Sattan's documentation by sharing this foolproof technique I came up with in Blender to create classic handrails, as well as some other tips I picked up from the helpful folks in the THPSX Discord channel.

This tutorial is going to assume that you already have Blender, the Thug Tools plugin, and have a decent grasp on the material covered in Sattan's basic level creation tutorial.
If you haven't, I recommend you start here:
http://thpsx.com/forums/index.php?topic=694.0

Moving along, let's get right into this rail creation technique that I'm eager to share with you.

PART 1 - Shaping the Rail

1) Go to object mode and create a basic cube.
(https://i.imgur.com/yn4EJ7q.png)

2) Go to edit (tab) and vertex mode. Hit A and make sure all 8 points of the cube.  Hit ALT+M and enter to merge all points at the center point.  The point of this is to create one single vertex/dot.
(https://i.imgur.com/ehJbZP7.jpg)

3) Assuming you are working with just one vertex now, make sure it's selected and hit E to 'extrude'. Move your new point around, using the keys X and Y to lock along the axis as needed to keep your rail straight if desired, then hit ENTER when your new rail point is where you want it.  Assuming you can get the hang of this and navigate and whatnot, this is going to be how you shape and dictate the path of your rail.
(https://i.imgur.com/s3v5k3A.jpg)

4) Now we're going to make the support posts of the rail.  Assuming you're fluent in selecting points and extruding, select all the points of the rail where you want the vertical supports at, press E to extrude, and Z to lock to the vertical axis so that you can drag all the points down into to floor level.
(NOTE: This must be done one vertex at a time. If you try to extrude multiple points at a time, Blender will go bonkers and not perform the desired task.)
(https://i.imgur.com/IvQ8LiQ.png)

5) Your rail path should look something like this when you're done. 
Now in Object mode, in the right menu, click the little wrench button to open the Modifiers menu.  We're going to add a Modifier that will turn this into a proper rail.
(https://i.imgur.com/uO4Ws9x.jpg)

6) Select the SKIN modifier. 
(https://i.imgur.com/er3ZemN.jpg)

7) Boom, now it's starting to look like a proper rail.
But you might notice it's a little too thick for your liking.  To change the thickness of your rail, go to edit mode, line/edge mode, and hit A to select all your lines.  Hit CTRL+A and drag your mouse a bit to change the thickness of your rail.  (This may take some getting used to, but if you can't figure it out just google some tutorials on using the Skin Modifier in Blender.)
(https://i.imgur.com/TX62dt3.jpg)

8) Now that we've got the rail looking how we want it, and assuming you are happy with the path of your rail (because it might be difficult to change after this step), go back to Object Mode and the Modifier menu and click "APPLY".  This is going to apply the modifier and make your rail a proper mesh.
(https://i.imgur.com/SDaISEc.jpg)

9) This next step is crucial so don't overlook it.  You may have noticed that our rail has a surplus of unnecessary polygons, which is bad news for performance.  But don't worry, we'll fix that in the next step. 
(https://i.imgur.com/bDV8uW0.jpg)

10) Select your rail in object mode and go back to the modifier menu.  We're adding the Decimator modifier to cleanly, efficiently, and instantly lower our poly count.
(https://i.imgur.com/UgtaHqK.jpg)

11) Select PLANAR mode in the modifier menu.  It will instantly do what you want it to do. 
Then hit APPLY.
(https://i.imgur.com/qXytJ5d.jpg)

12) We're now done with the actual shape of the rail itself.  Throw a UV texture on there, then in Object mode, select your rail and navigate to the THUG Tools menu on the left of your window. 
Make sure that "Export to Scene" is checked but that "Export to Collisions" is unchecked.
I'll explain why in the next section.
(https://i.imgur.com/EuJotcs.jpg)

PART 2 - Adding collision to the rail
As you know from Sattan's tutorial, the THUG2 engine is finicky about collisions, so we're going to generate a new object for our rail collision in just a few simple steps.

1) This first step is the most important so follow closely.  Select your current rail object, go to edit mode (TAB), and then go to Face Selection mode.  Select all of the flat TOP faces of your rail only.
Hit SHIFT-D (to duplicate) and immediately hit ENTER to lock the location, and without deselecting, hit P and ENTER to create a new object.
(https://i.imgur.com/8hJymRk.png)

2) Go to Object mode (TAB) and select your new rail-top object that you just created.  Be careful not to select the rail itself.
Go to Editing mode (TAB) and face selection and hit A to select all the faces, which should be one continuous line of faces along the rail's top only. 
Hit E to extrude and Z to lock to the vertical axis.  Just drag 'em straight into the ground, assuming it's not getting in the way of anything beneath.  You should now have a solid collision box along your rail. 
(https://i.imgur.com/JE3tO2i.jpg)

3) To make sure that the collision box is invisible in game and that the rail itself is seen in all of its glory, select your new rail top object and go to your THUG Tools menu.  You are going to do the reverse of what you did earlier. 
MAKE SURE that Export to Collisions is CHECKED and Export to Scene is UNCHECKED.
(https://i.imgur.com/6TJisJw.jpg)

4) Assuming you paid attention to Sattan's tutorial and have 'Backface Culling' enabled, and understand that only outer faces register collision in THUG, you may need to select your collision box's faces, click MESH>Normals>Flip Normals.
Make a mental note to come back to this step if you find yourself getting stuck inside your rail or the collision doesn't work as expected.
(https://i.imgur.com/hwDobxV.jpg)

PART 3 - Rail Nodes
Your rail is basically done at this point, but if you've tested your map you may have noticed that you can't actually grind it.  There are two ways to make a rail grindable, the first is by using mark rail, which you should have already learned if you're reading this tutorial, and the second is using nodes.  We're using nodes because they give us more options and versatility in the long run.

1) Select your rail object.  Go to edit mode and select ONE continuous outer line.  Imagine this line as the part of the rail that the player can actually grind on, so naturally you don't want corners. 
In the THUG Tools menu, click EXTRACT RAIL.  This is going to make a rail node out of your selected edge. 
(https://i.imgur.com/cHJ2PXI.png)

2) You should now have this dorky looking tube.  It's your rail node.  Make sure it's selected in Object mode.
(https://i.imgur.com/AVwDGO2.jpg)

3) We now have to align the rail node to your rail.  This part can be tedious if you don't know what you're doing.  Hit G to start moving, and X, Y, or Z to lock the axis and hit enter when you're done.
Because the 'Extract Rail' tool creates fat rail nodes, you're going to want to position your rail node so that the actual rail in the CENTER of the fat tube.  It should look like this.
(https://i.imgur.com/SUn9kqc.png)

4) Test out your map and adjust as needed, then you're done with your rail. 

Perfection.
(https://i.imgur.com/SbjbOHL.jpg)

PART 4 - Making your rail taggable in Graffiti

1) Select your rail object.  In the THUG Tools menu, check "Is a TrickObject".  This tells the game that you can mark this object in graffiti.  Because our Rail Node is a separate object from the rail itself, and because the rail itself has no collision or grind-ability of its own, it is VERY IMPORTANT that you fill in the cluster with a value that will link the two objects.  I chose hall_rail, all lowercase.

2) Repeat the same exact step for your rail node.  Both the rail object and the rail node object should have these same exact values applied.  That's it.  Your rail now works in graffiti. 
(https://i.imgur.com/zqHbxSs.png)

PART 5 - Rail Boosts
This step is entirely optional
Rail boosts are only used sparingly in situations where the player cannot get enough velocity to clear a rail, or you want them to grind upwards while defying gravity. 
Be careful with these because they can make or break a rail.

1) Select your rail node. In object mode, go to your THUG Tools menu. Click "TRIGGER SCRIPT" and "CUSTOM".
(https://i.imgur.com/22btFuQ.png)

2) Now click Create TriggerScript
(https://i.imgur.com/fgN2BLy.png)

3) To edit the script, you will need to go to script editing mode. Do that by clicking this dropdown at the top of your Blender window.
(https://i.imgur.com/3Z4ng97.png)

4) At the bottom of your script editing window, make sure you select the right script: The one you just created.
(https://i.imgur.com/9PyuBjR.png)

5) Now that you have your corresponding rail script selected, paste the following code into your script editor:

Code: [Select]
    :i $RailAccelerate$:s{
    :i $rate$ = %f(0.100000)
    :i :s}

(https://i.imgur.com/5SAIlXx.png)

(NOTE: You can change the speed of the boost by modifying the $rate$ variable.
0.100000 should be enough for most cases, but if you know what you're doing you can modify this value.)

That's it.  Hope it helps. :)