Jump to content


Photo

Creating a Robust Tram Script


64 replies to this topic

#1 Epifire

Epifire

    Member

  • Active Developer
  • PipPip
  • 388 posts

Posted 16 May 2017 - 03:44 AM

Well I'd talked a tad bit about starting a tram with my splines thread but I thought I'd post something a little more direct now. For you script junkies I hope this can be a fun little project to collaborate on! So here it goes. The tram I'm making for my mission will be a self powered mode of transportation that rides along a railway. It should basically be a small box car of sorts with a view panel that stretches around all sides. It should have a single door that is automatically closed while the tram is in motion. It should have three buttons for controlling it. Forward, backward and a brake. The directional levers should only be able to change direction when the brake has been applied (so no changing directions while in motion!).

 

The tram brake should probably be it's own script function so that it can be called by other modes of command (from end of path splines or triggered events). It also should have a single state that (when enabled) should make the controls inoperable. This function is only needed so that the tram may carry out it's last defined spline path without player interference. Lastly, I wanted to have a true/false active state available. This is just so that the tram can remain inactive until the story/objectives define otherwise.

 

I will be modeling a entirely new detail mesh from scratch, and I'm hoping that I can eventually get a pretty compact def file established for it. The end goal of mine is to have a nice tram that practically anyone can pick up and use after it ships in my FM.

 

Also for your convenient referencing I already grabbed the original script for the D3 tram and tried to gut most the features I was sure that we wouldn't be needing for this. Such as vertical and lateral movement functions. Hoping we can reuse some functions from it but I'm a script novice so I need some parental advice.  :P

 

Spoiler

Needing dem environment models?

 

Speak to the EPI!

 

Or rummage my online mesh repository instead...  https://www.mediafire.com/folder/7q1r8him1y63d/TDM%20Repository


#2 Obsttorte

Obsttorte

    Scripting guru, Mapper

  • Active Developer
  • PipPipPipPipPip
  • 5151 posts

Posted 16 May 2017 - 04:16 AM

The lifts in D3 moved in straight lines. As far as I remember you want your tram to move in curves. So up-down and left-right will also include rotation.

 

Personally I wouldn't use splines for such an undertaking bould would rather rely on a fixed set of tracks which hold the information needed for correct movement. This would allow to use a script to provide the correct setup, instead of the mapper having to setup all the links, targets etc. which would be quite messy with bigger rail systems and not very error prone. In addition a tram has a considerable length, so the center of the tram will not be following the center of the rails when driving through curves for example.

 

Regarding the tram it would be you should think about whether the player can see the tram moving from the outside or not. If not, the wheels don't need to be seperate models. However, in terms of reusability it might make sense to make them seperate models anyway. What is important though is what kind of axe system you are going to use. I'm assuming you would go for a two axle vehicle, so one axle at the front and one at the back?! In that case you should make sure that the origin of the tram model is exactly in the center of both axles, preferable at the same height where the wheels touch the rails. This would easen the math for the rotation. If you are aiming for a tram that has two axles both at the front and the back, things will get a bit more messy.

 

Just my two cents, though.


FM's: Builder Roads, Old Habits, Old Habits Rebuild
WIP's: Several. Although after playing Thief 4 I really wanna make a city mission.
Mapping and Scripting: Apples and Peaches
Sculptris Models and Tutorials: Obsttortes Models
My wiki articles: Obstipedia
Let's Map TDM YouTube playlist: ObstlerTube
Texture Blending in DR: DR ASE Blend Exporter

End of shameless self promotion.

#3 Epifire

Epifire

    Member

  • Active Developer
  • PipPip
  • 388 posts

Posted 16 May 2017 - 03:32 PM

Splines have to be used because the regular mover paths don't take pitch into account. For angles and such it requires that it uses a spline, otherwise I'm stuck working on a level plane.

 

To be fair most the areas setup for the tram are just single paths without any optional turns or routes. The big thing I want to make sure is bulletproof is that it can stop and continue or change directions with ease. Right now I don't seem to have an effective means of stopping without it starting the spline path over again.

 

Unlike the door, the wheel movers aren't essential to start with but I would like to add them later when the core components are in. I'm really just wondering how to get all of this setup.


Needing dem environment models?

 

Speak to the EPI!

 

Or rummage my online mesh repository instead...  https://www.mediafire.com/folder/7q1r8him1y63d/TDM%20Repository


#4 Obsttorte

Obsttorte

    Scripting guru, Mapper

  • Active Developer
  • PipPipPipPipPip
  • 5151 posts

Posted 16 May 2017 - 03:58 PM

In that regard I might add that for splines you should make sure that the radii of the curves should be sufficiently bigger then the length of the tram, so that the offset that is caused by them can be ignored. Otherwise you will have a hard time getting them layed out correctly.

 


Splines have to be used because the regular mover paths don't take pitch into account

I've never said anything about regular movers and am not sure what you mean by that. I've meant that the script posted will probably not work as it is intented for a completely different kind of situation.


FM's: Builder Roads, Old Habits, Old Habits Rebuild
WIP's: Several. Although after playing Thief 4 I really wanna make a city mission.
Mapping and Scripting: Apples and Peaches
Sculptris Models and Tutorials: Obsttortes Models
My wiki articles: Obstipedia
Let's Map TDM YouTube playlist: ObstlerTube
Texture Blending in DR: DR ASE Blend Exporter

End of shameless self promotion.

#5 Epifire

Epifire

    Member

  • Active Developer
  • PipPip
  • 388 posts

Posted 16 May 2017 - 04:23 PM

In that regard I might add that for splines you should make sure that the radii of the curves should be sufficiently bigger then the length of the tram, so that the offset that is caused by them can be ignored. Otherwise you will have a hard time getting them layed out correctly.

 

 

I've never said anything about regular movers and am not sure what you mean by that. I've meant that the script posted will probably not work as it is intented for a completely different kind of situation.

 

I meant just the regular method being defined by path nodes. For the spline itself I can imagine there will be a lot of map testing involved to get the desired positioning down. Just in my own side tests I realized just how sharp it will make turns. One thing was bothering me when I had made a static brush bucket to test with. When turning or moving at an angle, the player somehow could block the mover from the inside. I'm hoping that just had to do with using brushwork, so hopefully using a model should fix that.

 

So to start with, how would we go about setting up these three main buttons?


Needing dem environment models?

 

Speak to the EPI!

 

Or rummage my online mesh repository instead...  https://www.mediafire.com/folder/7q1r8him1y63d/TDM%20Repository


#6 Obsttorte

Obsttorte

    Scripting guru, Mapper

  • Active Developer
  • PipPipPipPipPip
  • 5151 posts

Posted 17 May 2017 - 01:58 AM

I was more thinking about a func_mover. An entity whichs movements are4 controlled via scripting.

 

The same applies to the buttons. You could for example use the state_change_callback or work with the triggers they cause (I prefer the latter). If you take a look at the numberwheel lock in Builder Roads you can see how the script works (although this version is a bit buggy).

 


For the spline itself I can imagine there will be a lot of map testing involved to get the desired positioning down.

That's why I suggested to use a different approach. IIRC in Doom3 they were never used for movers, but for camera movement only (ingame cutscenes). If the railworks become sufficiently large, it will be a hard thing to avoid errors.


FM's: Builder Roads, Old Habits, Old Habits Rebuild
WIP's: Several. Although after playing Thief 4 I really wanna make a city mission.
Mapping and Scripting: Apples and Peaches
Sculptris Models and Tutorials: Obsttortes Models
My wiki articles: Obstipedia
Let's Map TDM YouTube playlist: ObstlerTube
Texture Blending in DR: DR ASE Blend Exporter

End of shameless self promotion.

#7 NeonsStyle

NeonsStyle

    Advanced Member

  • Member
  • PipPipPip
  • 1249 posts

Posted 17 May 2017 - 03:01 AM

Sounds fun, wish I knew what a spline was in this context. 


I have a small YouTube channel making videos on a variety of games. Come and have look here:
 
https://www.youtube.com/c/NeonsStyleHD

 

 

 


#8 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1258 posts

Posted 17 May 2017 - 03:10 AM

Sounds fun, wish I knew what a spline was in this context. 

http://wiki.thedarkm...Camera_Movement



#9 Epifire

Epifire

    Member

  • Active Developer
  • PipPip
  • 388 posts

Posted 17 May 2017 - 03:18 AM

I was more thinking about a func_mover. An entity whichs movements are4 controlled via scripting.

 

The same applies to the buttons. You could for example use the state_change_callback or work with the triggers they cause (I prefer the latter). If you take a look at the numberwheel lock in Builder Roads you can see how the script works (although this version is a bit buggy).

 

Currently it's using func_mover_amodel with a state_change_callback on a button. The problem at current, is it doesn't pick up where it left off. It just restarts the spline path rather than resuming course.

 

Baring in mind that the tram doesn't deviate from a single spline path in any given situation, should it really be that difficult to implement? Maybe I'm assuming the script can do more than I'm seeing, or that it simply can't handle complex commands for splines. I was under the impression you could define start and end point entities similar to conventional multistate movers. The only difference being how it converges between those two points being a spline rather than a straight line.

 

 

Sounds fun, wish I knew what a spline was in this context. 

Proof of concept that a one way mover does indeed work.

https://gyazo.com/96...a882a9ff3320f23


Needing dem environment models?

 

Speak to the EPI!

 

Or rummage my online mesh repository instead...  https://www.mediafire.com/folder/7q1r8him1y63d/TDM%20Repository


#10 Obsttorte

Obsttorte

    Scripting guru, Mapper

  • Active Developer
  • PipPipPipPipPip
  • 5151 posts

Posted 17 May 2017 - 04:24 AM


Baring in mind that the tram doesn't deviate from a single spline path in any given situation, should it really be that difficult to implement?

It is not neccessarely hard, but there are a few things to consider. What I don't get is why you insist on using splines?! They are not meant for that purpose, as said.


FM's: Builder Roads, Old Habits, Old Habits Rebuild
WIP's: Several. Although after playing Thief 4 I really wanna make a city mission.
Mapping and Scripting: Apples and Peaches
Sculptris Models and Tutorials: Obsttortes Models
My wiki articles: Obstipedia
Let's Map TDM YouTube playlist: ObstlerTube
Texture Blending in DR: DR ASE Blend Exporter

End of shameless self promotion.

#11 Epifire

Epifire

    Member

  • Active Developer
  • PipPip
  • 388 posts

Posted 17 May 2017 - 12:09 PM

It is not neccessarely hard, but there are a few things to consider. What I don't get is why you insist on using splines?! They are not meant for that purpose, as said.

 

Because as far as I know of it's the only pathing method that can incorporate pitch control. The track and rail areas needed to be traversed have a lot of vertical height differences. If the normal method could do that easily, I'd just as well chuck splines. From what everyone was telling me though, splines are the only way to accomplish that.

What would be the few things to consider?


Needing dem environment models?

 

Speak to the EPI!

 

Or rummage my online mesh repository instead...  https://www.mediafire.com/folder/7q1r8him1y63d/TDM%20Repository


#12 Obsttorte

Obsttorte

    Scripting guru, Mapper

  • Active Developer
  • PipPipPipPipPip
  • 5151 posts

Posted 17 May 2017 - 02:11 PM

What would be the few things to consider?

For example the ratio of the distance between the front and the rear axis and the minimum radius of your curves.


FM's: Builder Roads, Old Habits, Old Habits Rebuild
WIP's: Several. Although after playing Thief 4 I really wanna make a city mission.
Mapping and Scripting: Apples and Peaches
Sculptris Models and Tutorials: Obsttortes Models
My wiki articles: Obstipedia
Let's Map TDM YouTube playlist: ObstlerTube
Texture Blending in DR: DR ASE Blend Exporter

End of shameless self promotion.

#13 Epifire

Epifire

    Member

  • Active Developer
  • PipPip
  • 388 posts

Posted 17 May 2017 - 03:22 PM

For example the ratio of the distance between the front and the rear axis and the minimum radius of your curves.

 

As long as the rails aren't bizarre the curves should be able to be tweaked to match pretty easily. My only real concern was the unpredictable amount of roll axis tilt that occurs on hard turns along an incline. I had tried running $mover_object.disableSplineAngles(); but that seems to disable all axis of rotation. Pitch and yaw are the only two axis that the spline seems to handle in a reasonable fashion. However if there's not a lot of control options there, I can work around the problem of intense roll if I keep inclines and turns separated.

Right now though, I'm just trying to get some usable functions for the buttons fleshed out. That's the main running theme that the tram must have to function. After that I'd look at an automatic door and wheels, since those are more a last step. I was really wanting to smartly include the tram for accessing, what would otherwise be out of reach areas. So that's why the stop and start buttons are so important. The key to their functionality is that it can't change directions on a dime. Example: if moving forward the reverse direction lever would check to see if stopped before being able to move to the opposite end of the track. Maybe insert a metallic grinding sound affect on a false attempt.


Needing dem environment models?

 

Speak to the EPI!

 

Or rummage my online mesh repository instead...  https://www.mediafire.com/folder/7q1r8him1y63d/TDM%20Repository


#14 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1258 posts

Posted 17 May 2017 - 03:36 PM

Do we have (or can we implement) a three-state-lever? In this case you could have "forward" for example to the left. From this position, the only option is "stop"in the middle. From here, it goes on to "backwards" to the right. And the same in the other directon. Thus, you would not need three buttons and the direction check is automatically implemented. The only downside I could see is, that the lever has to cycle through all states, as it is not possible to determine in which direction the lever should go by a simple frob. So, if you want to go forward, stop and continue forward, you would have to go backwards first.

Another option for a forced stop could be frobability. I.e. when the tram moves only the "stop" button is frobable, when it stands still, the other two buttons are frobable. May be even simpler than the lever, now that I think about it...



#15 nbohr1more

nbohr1more

    Darkmod PR, Wordsmith

  • Development Role
  • PipPipPipPipPip
  • 7801 posts

Posted 17 May 2017 - 04:02 PM

I think our elevator code is 3 state (at least)

http://wiki.thedarkm...rs,_multi-floor
Please visit TDM's IndieDB site and help promote the mod:

http://www.indiedb.c...ds/the-dark-mod

(Yeah, shameless promotion... but traffic is traffic folks...)

#16 Epifire

Epifire

    Member

  • Active Developer
  • PipPip
  • 388 posts

Posted 17 May 2017 - 05:15 PM

Do we have (or can we implement) a three-state-lever? In this case you could have "forward" for example to the left. From this position, the only option is "stop"in the middle. From here, it goes on to "backwards" to the right. And the same in the other directon. Thus, you would not need three buttons and the direction check is automatically implemented. The only downside I could see is, that the lever has to cycle through all states, as it is not possible to determine in which direction the lever should go by a simple frob. So, if you want to go forward, stop and continue forward, you would have to go backwards first.

Another option for a forced stop could be frobability. I.e. when the tram moves only the "stop" button is frobable, when it stands still, the other two buttons are frobable. May be even simpler than the lever, now that I think about it...

 

I hadn't thought of a three stage switch before. It looks like these all check an order, so couldn't the forward/backward modes toggle back to the brake if these values were adjusted? That essentially would be what we need. Visually it would make sense too because you couldn't put it in a different gear without tripping the brake first. For the brake I'm very curious as to how that could work. Everything I've heard so far points to the fact that it needs a solid defined point of origin to end a script on. Whereas I just want to be able to halt it on the fly.

 

This is the current little bit of script the spline mover type requires for one way direction right now.

void spline_mover()
{
	$mover_object.time(30); 		 //how long object take to move along spline
	$mover_object.accelTime(2); 		 //time mover takes to accelerate to full speed range 0.0 to not more than time to travel spline
	$mover_object.decelTime(0.5);		 //time mover takes to decelerate to a stop range as above
	//$mover_object.disableSplineAngles(); 	 //disables spline angles
	$mover_object.startSpline($spline_path); //starts mover moving along spline
	sys.waitFor($mover_object); 	         //wait for func_mover to finish moving along spline before doing anything else
}

Needing dem environment models?

 

Speak to the EPI!

 

Or rummage my online mesh repository instead...  https://www.mediafire.com/folder/7q1r8him1y63d/TDM%20Repository


#17 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1258 posts

Posted 18 May 2017 - 01:50 AM

I hadn't thought of a three stage switch before. It looks like these all check an order, so couldn't the forward/backward modes toggle back to the brake if these values were adjusted? That essentially would be what we need.

I think, this is what I meant. With a three stage switch, you would automatically switch from forward or backward to the stop position. The problem with the order I meant, was that you can not simply stop and continue in the same direction that way, because you can only frob the switch, but you can not give a direction in which the switch schould move. Unless, you want to introduce a GUI, when you activate the lever in the stop position, that asks, which direction you want to go...

 

Regarding the break, I alos have no idea how to implement it on a spline. If it is possible to read out the current direction, in which the mover moves, as a vector, it may be possible to define a new end point relative to the current position. In a simple way something like "Breakpoint = $Mover.getOrigin() + 10*directionVector" (this is not correct syntax; I am not very familiar with scripting) and then set the current destination to this Breakpoint.


  • Epifire likes this

#18 Epifire

Epifire

    Member

  • Active Developer
  • PipPip
  • 388 posts

Posted 21 May 2017 - 01:10 AM

Regarding the break, I alos have no idea how to implement it on a spline. If it is possible to read out the current direction, in which the mover moves, as a vector, it may be possible to define a new end point relative to the current position. In a simple way something like "Breakpoint = $Mover.getOrigin() + 10*directionVector" (this is not correct syntax; I am not very familiar with scripting) and then set the current destination to this Breakpoint.

 

Honestly the syntax is what I'm having the most difficulty with right now. I don't fully understand what commands are all available to utilize in a format the game will understand. Usually there's some sort of fallback archive I can find that documents available functions and brief explanations (much like the mtr documentation) but alas I can find none. If all else fails I may very well just have to settle for a single trip button loop. In this scenario we'd just have one throw switch in the control panel that would take you all the way to your destination. Upon arrival the button would toggle over to another script activation, so when triggered again you'd just hop on an identical path that's just the same path but reversed.

If there was some sort of .startSplineReverse command that'd make that whole bit easier. Just have it check for position and kick in the reversal script if the tram is at end of the spline. Again I don't even know if that function exists so I'm flying blind. At worst I'd just make the duplicate path running backwards, but I'm really trying to save that option as a last resort if there's no other option.


Needing dem environment models?

 

Speak to the EPI!

 

Or rummage my online mesh repository instead...  https://www.mediafire.com/folder/7q1r8him1y63d/TDM%20Repository


#19 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1258 posts

Posted 21 May 2017 - 05:00 AM

For the (few and very basic) things I have done regarding scripting, I have used a combination of the scripting tutorial on the Wiki, that unfortunately is not finished, but at least gives a basic understanding, of how scripting works, and a list of available script commands on the Wiki. The latter is vast and it is not easy to find what you need, but the search function of your browser helps in this regard.


  • Epifire likes this

#20 Epifire

Epifire

    Member

  • Active Developer
  • PipPip
  • 388 posts

Posted 21 May 2017 - 01:29 PM

Awwww yis! That list is exactly what I was needing. Already dug out a great find from that. Turns out you can disable just the roll factor in a spline mover if you just add .removeInitialSplineAngles (instead of disableSplineAngles). That's one annoying thing fixed. Not seeing a lot else relating to movers thus far. I think I'll try the basic two way setup first, and see what could be possible to add after that. There is a stop command relating directly to splines, but I have my doubts as to whether it will just restart the path if enabled again. I'll have to try and bind some buttons to my test mover and see if I can actually continue a path.


Needing dem environment models?

 

Speak to the EPI!

 

Or rummage my online mesh repository instead...  https://www.mediafire.com/folder/7q1r8him1y63d/TDM%20Repository


#21 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1258 posts

Posted 21 May 2017 - 03:21 PM

I am glad, that this helped :)



#22 Epifire

Epifire

    Member

  • Active Developer
  • PipPip
  • 388 posts

Posted 26 May 2017 - 07:42 PM

Alright so I'm just taking this one on the simple route, as I don't wanna cut it but I don't see any practical means of resuming (or reversing) a spline mover. I'm content with a two button call system but I wanna make it visually informative as well as fool proof. 

 

Current problems are...

 

Track reversal: This I may have covered but not thoroughly tested for a fix. The problem lies in the fact that when switching to the identical spline (ran the other way) is that the mover will flip to face it. This is an inherit problem with how the spline angles are implemented. I think it can however be overcome by toggling in a identical tram model that has inverted forward axis. The result should be instantaneous without a noticeable hitch. Even if it is slightly more work.

 

Player Still Dies a Lot: So it's not exactly unheard of but on the same note as the last problem; when switching directions, the, "flip" tends to kill the player for some reason. This may be given that I've been testing with, "4posterbed.lwo" and you can't fully stand in it. Possibly just more headroom is needed when I make the actual mesh so that there is standing room.

 

Button Active States: One track is ran on a forward button and the other track is ran on the backward switch. These buttons need to have two conditions to work flawlessly. Firstly they can only trigger once (when idle at the spline start). They cannot be re-activated during transit other wise it will teleport to start as well as kill the player. I think if done right, either button will trigger once and will reset the other button when the the tram has come to a stop (possibly fired from sys.waitFor in said button script?). Done correctly it should be able to flipflop between the two modes whenever you reach the other platform.

 

Call Buttons: This should be extremely similar if not even using the same scripts derived for the aforementioned button functions. The only condition here is that the call button must not be able to call the tram until it has reached the opposite platform.

 

If I can iron out some example lines for the last two problems here, I think that'll be my biggest worry out of the way.


Needing dem environment models?

 

Speak to the EPI!

 

Or rummage my online mesh repository instead...  https://www.mediafire.com/folder/7q1r8him1y63d/TDM%20Repository


#23 Obsttorte

Obsttorte

    Scripting guru, Mapper

  • Active Developer
  • PipPipPipPipPip
  • 5151 posts

Posted 27 May 2017 - 07:31 AM

RE track reversal. Have you tried negative speed values?


FM's: Builder Roads, Old Habits, Old Habits Rebuild
WIP's: Several. Although after playing Thief 4 I really wanna make a city mission.
Mapping and Scripting: Apples and Peaches
Sculptris Models and Tutorials: Obsttortes Models
My wiki articles: Obstipedia
Let's Map TDM YouTube playlist: ObstlerTube
Texture Blending in DR: DR ASE Blend Exporter

End of shameless self promotion.

#24 Epifire

Epifire

    Member

  • Active Developer
  • PipPip
  • 388 posts

Posted 27 May 2017 - 01:36 PM

Yeah it didn't seem to have any affect adding a negative spawnarg to the mover. It just created a crash if I tried to input them via script.


Needing dem environment models?

 

Speak to the EPI!

 

Or rummage my online mesh repository instead...  https://www.mediafire.com/folder/7q1r8him1y63d/TDM%20Repository


#25 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1258 posts

Posted 28 May 2017 - 05:06 AM

Track reversal: This I may have covered but not thoroughly tested for a fix. The problem lies in the fact that when switching to the identical spline (ran the other way) is that the mover will flip to face it. This is an inherit problem with how the spline angles are implemented. I think it can however be overcome by toggling in a identical tram model that has inverted forward axis. The result should be instantaneous without a noticeable hitch. Even if it is slightly more work.

 

Player Still Dies a Lot: So it's not exactly unheard of but on the same note as the last problem; when switching directions, the, "flip" tends to kill the player for some reason. This may be given that I've been testing with, "4posterbed.lwo" and you can't fully stand in it. Possibly just more headroom is needed when I make the actual mesh so that there is standing room.

I think this is strange, if you don't move a spline anymore. When you take a look at elevators, they do not flip, when the movement is reversed. So, if you just use a simple func_mover (as I think you do, regarding your first comment) there should be no switch, unless I am missing something here.





Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users