Animated Objects: Following The Track- Now with SOUND!

View previous topic View next topic Go down

Animated Objects: Following The Track- Now with SOUND!

Post by leezer3 on Sat Aug 27, 2016 1:16 pm

The most recent build of openBVE now has a new function available for use in animated objects-
TrackFollowerFunction

One of the biggest problems in animating a moving train (Or other item!) is that previously we couldn't go around corners, or up hills.

TrackFollowerFunction provides a considerable improvement on this, as follows:

  • The result of this function should be the distance in meters for which we wish the object to be translated.
  • This translation is then applied along the path of Rail 0.
  • Finally, any other translations & rotations (From TranslateXFunction etc.) are applied to give the object's final position.


Limitations:

  • Only Rail 0's path is supported.
  • Horizontal & vertical positioning of the object must be done via the Position command in your .animated file, **not** via the routefile.
  • Sharp curves don't work as well as loose curves.
  • The further horizontally you go from Rail 0, the worse the results- Both of these are to do with the fundamental mathematical principle that a curve with a different radii will have a different length Razz


Finally, the video:


Cheers


Last edited by leezer3 on Fri Jan 20, 2017 2:27 pm; edited 1 time in total

leezer3

Posts : 969
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by leezer3 on Sat Aug 27, 2016 1:30 pm

For reference, this is the code used in the animation above:
Code:
[Object]
States = ..\cl47_Intercity_Swallow\47826_A.csv
Position = 4,0,0
TrackFollowerFunction = -mod[10 * time, 1000] + 5

;Coach 1
[Object]
States = ..\coaches\GUV_blue_n.b3d
Position = 4,0,0
TrackFollowerFunction = -mod[10 * time, 1000] + 24.8

;Wheelset1
[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 16.5

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 18.9
[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 30.7

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 33.1

;Coach 2
[Object]
States = ..\coaches\mk1_bk_itc_n.b3d
Position = 4,0,0
TrackFollowerFunction = -mod[10 * time, 1000] + 44.8

;Wheelset2
[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 36.5

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 38.9

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 50.7

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 53.1

;Coach 3
[Object]
States = ..\coaches\mk1_FO_itc_n.b3d
Position = 4,0,0
TrackFollowerFunction = -mod[10 * time, 1000] + 64.8

;Wheelset3
[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 56.5

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 58.9

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 70.7

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 73.1

;Coach 4
[Object]
States = ..\coaches\mk1_FO_itc_n.b3d
Position = 4,0,0
TrackFollowerFunction = -mod[10 * time, 1000] + 84.8

;Wheelset4
[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 76.5

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 78.9

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 90.7

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 93.1

;Coach 5
[Object]
States = ..\coaches\mk1_TSO_blue_n.b3d
Position = 4,0,0
TrackFollowerFunction = -mod[10 * time, 1000] + 104.8

;Wheelset5
[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 96.5

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 98.9

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 110.7

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 113.1

;Coach 6
[Object]
States = ..\coaches\mk1_TSO_blue_n.b3d
Position = 4,0,0
TrackFollowerFunction = -mod[10 * time, 1000] + 124.8

;Wheelset6
[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 116.5

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 118.9

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 130.7

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 133.1

;Coach 7
[Object]
States = ..\coaches\mk1_FO_itc_n.b3d
Position = 4,0,0
TrackFollowerFunction = -mod[10 * time, 1000] + 144.8

;Wheelset7
[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 136.5

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 138.9

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 150.7

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 153.1

;Coach 8
[Object]
States = ..\coaches\mk1_BCK_blue_n.b3d
Position = 4,0,0
RotateYFunction = 3.14159265
TrackFollowerFunction = -mod[10 * time, 1000] + 164.8

;Wheelset8
[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 156.5

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 158.9

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 170.7

[Object]
States = ..\wagons\wheelset_solid.b3d
Position = 4,0.425,0
TrackFollowerFunction = -mod[10 * time, 1000] + 173.1

You'll note that the offset for each coach/ wheelset is added to the result of the TrackFollowerFunction- This is to ensure that they're correctly offset when on the bend.
The X position value of 4 is needed to move our objects to the adjacent track.

Cheers

leezer3

Posts : 969
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by phontanka on Sat Aug 27, 2016 3:32 pm

Yeeeaaah!

avatar
phontanka

Posts : 242
Join date : 2012-05-08
Location : Hungary

http://phontanka.wordpress.com

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by phontanka on Sat Aug 27, 2016 4:13 pm

OK, here's a nicer video, with the arrival and departure of a Királyliget bound train, and in between an oncoming Sólyomvár bound train arrives as well. Great stuff, Chris!

avatar
phontanka

Posts : 242
Join date : 2012-05-08
Location : Hungary

http://phontanka.wordpress.com

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by phontanka on Sat Aug 27, 2016 4:42 pm

Can I ask for some help? I'm not very good at animation scripts. What I'd like to reach is that the oncoming train with the TracFollowerFunction ran only once, and that would be when the train I'm driving gets to a certain distance from it. Is this possible, or will it always re-appear again in cycles?

Here's the Siemens Desiro I used in the videos: https://dl.dropboxusercontent.com/u/51947703/BVE/Desiro-TrackFollowerFunction.7z
avatar
phontanka

Posts : 242
Join date : 2012-05-08
Location : Hungary

http://phontanka.wordpress.com

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by leezer3 on Sat Aug 27, 2016 10:40 pm

This is a somewhat hacky solution to your problem:
Code:
TrackFollowerFunction = if[value == 0, value + 1000, if[value < 0, value, value - 10 * delta]]

A breakdown of the function:
if[value == 0, value + 1000, if[value < 0, value, value - 10 * delta]]
This is the 'hacky' part- We're relying on the fact that the value will only ever equal zero when the object is first loaded by the renderer.

if[value == 0, value + 1000, if[value < 0, value, value - 10 * delta]]
When the condition is met, move our object 1000m forwards.

if[value == 0, value + 1000, if[value < 0, value, value - 10 * delta]]
Otherwise, test if our value is greater than zero.

if[value == 0, value + 1000, if[value < 0, value, value - 10 * delta]]
If true, just return the value (Don't move the object)

if[value == 0, value + 1000, if[value < 0, value, value - 10 * delta]]
If false, take away 10 multiplied by the time elapsed in seconds from the value to move the object towards us.

This is the same function, but moving the object in the same direction as the train:
Code:
TrackFollowerFunction = if[value == 0, value - 1000, if[value > 0, value, value + 10 * delta]]

leezer3

Posts : 969
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by phontanka on Sat Aug 27, 2016 10:59 pm

Cool, thanks! I'll give it a try right now!
avatar
phontanka

Posts : 242
Join date : 2012-05-08
Location : Hungary

http://phontanka.wordpress.com

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by phontanka on Sat Aug 27, 2016 11:30 pm

Great!

With this script it stops suddenly. Is it possible to make it brake down gradually?

And is it possible to get rid of the "AI" train after it's finished moving?
avatar
phontanka

Posts : 242
Join date : 2012-05-08
Location : Hungary

http://phontanka.wordpress.com

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by leezer3 on Sat Aug 27, 2016 11:45 pm

Braking smoothly will get complex fast Smile
This is a three speed-stepped formula (1000m to 100m, 100m  to 50m and 50m to 0m)
Code:
TrackFollowerFunction = if[value == 0, value - 1000, if[value > 0, value, if[value > -100,value + 20 * delta,if[value > -50,value + 10 * delta,value + 5 * delta ]]]]
(Untested, but should work, if not, you should be able to read across to see what it's doing)

I'll do some thinking, as I'm sure it's probably possible to do this better, but that's the best I can do off the top of my head.

Getting rid of the AI train is a little more complex.
For this you need a StateFunction
The easiest way to do this, is probably on a simple timer basis:
Code:
StateFunction = if[value + delta > 20, -1,0]
Simple enough- The object will be removed (Set to state -1) after 20 seconds. You'll obviously need to alter the timer to suit the length of the animation.

leezer3

Posts : 969
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by phontanka on Sat Aug 27, 2016 11:48 pm

Thanks, Chris.

And another question. Can this script be connected to the distance from the driveable train? I mean, with this script if I go to the F3 view and hop to the position of this "AI train" object using the camera forward (Num 7) button the "AI" train already starts moving. I'd prefer it to wait until the train I'm driving approaches that point.
avatar
phontanka

Posts : 242
Join date : 2012-05-08
Location : Hungary

http://phontanka.wordpress.com

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by leezer3 on Sun Aug 28, 2016 12:00 am

Sure Smile
Just requires another if condition.

Using the first function for a little clarity, hopefully you should be able to see the difference:
Code:
TrackFollowerFunction = if[value == 0, value + 1000, if[trackdistance > -200,if[value < 0, value, value - 10 * delta], value]]

All this has done is added a check as to whether the train is closer than 200m before doing anything.
Note:
I haven't checked whether Pretrains are considered a train for this.
This will be clarified when I've had time to check the code, and a separate variable provided to check for player trains and AI trains.
https://github.com/leezer3/OpenBVE/issues/91

leezer3

Posts : 969
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by phontanka on Sun Aug 28, 2016 12:31 am

I think pretrains are also considered, because a few seconds after the route loads I see the animation happening. Route.Runinterval is 1800, if that matters, but maybe not, I don't know. But, as a matter of fact there are no visible pretrains in the area of the animation, so that's funny.

Another thing: StateFunction = if[value + delta > 20, -1,0] doesn't seem to make the "AI" train disappear. This is what I have in my animated object, maybe I've done something incorrectly:

Code:
[Object]
position = -4,0,0
States = DESIRO1.B3D
StateFunction = if[value + delta > 20, -1,0]
TrackFollowerFunction = if[value == 0, value + 1000, if[trackdistance > -200,if[value < 0, value, value - 10 * delta], value]]

[Object]
position = -4,0,0
States = DESIRO2.B3D
StateFunction = if[value + delta > 20, -1,0]
TrackFollowerFunction = if[value == 0, value + 1000, if[trackdistance > -200,if[value < 0, value, value - 10 * delta], value]]

[Object]
position = -4,0,0
States = DESIROFORGO.B3D
StateFunction = if[value + delta > 20, -1,0]
TrackFollowerFunction = if[value == 0, value + 1000, if[trackdistance > -200,if[value < 0, value, value - 10 * delta], value]]
avatar
phontanka

Posts : 242
Join date : 2012-05-08
Location : Hungary

http://phontanka.wordpress.com

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by phontanka on Sun Aug 28, 2016 6:36 am

And what would be the best option to add sound to these TrackFollowerFunction trains? .Announce is not the best, because you don't know for sure what track position you meet them at.
avatar
phontanka

Posts : 242
Join date : 2012-05-08
Location : Hungary

http://phontanka.wordpress.com

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by leezer3 on Thu Sep 01, 2016 7:57 pm

Been rather busy, so didn't get back to this.....

I think these two will do what you want, combination of my mistake and the animation formulae system still being rather funky.....
Code:
StateFunction = if[trackdistance > 200, 0 , min[value + 0.5 * delta / 20 , 1]]
TrackFollowerFunction =  if[value == 0, value + 100, if[trackdistance > 200,value,if[value < 0, value, value - 10 * delta]]]

StateFunction:
That was my mistake, I'd forgotten that delta isn't cumulative, and hence you've either got to do some real nastyness with total time or the hack above.
The track position check could be done away with to leave this:
Code:
StateFunction = min[value + 0.5 * delta / 20 , 1]

This will produce odd effects if you reverse with the train still in view (It'll vanish after 20s no matter what), so I wouldn't reccomend this.

TrackFollowerFunction:
There's a bug hiding in the treatment of negative numbers which I haven't got to the bottom of yet which really wasn't helping working properly....

Sounds:
Absolutely no support at present Razz
This will come at some stage, but the sound triggering system is an absolute mess.

Improvise? Twisted Evil

leezer3

Posts : 969
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by Dexter on Fri Sep 02, 2016 11:29 pm

I like this! *thinks about a couple of hours tomorrow evening*
avatar
Dexter

Posts : 1836
Join date : 2011-07-08
Age : 31
Location : Brno, Czech republic

http://www.brnobve.eu

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by phontanka on Thu Dec 29, 2016 3:47 pm

I would like to ask for some help. I'm updating a route and I've added three trackfollower trains with the following code:

Code:
[Object]
position = -4,0,0
States = Traxx.csv
StateFunction = if[value + delta > 20, -1,0]
TrackFollowerFunction = if[value == 0, value + 1000, if[trackdistance > -200,if[value < 0, value, value - 10 * delta], value]]

Only the static object is different in them and the X position.

My problem is that the animation works correctly only on the first trackfollower train, the second and the third train is not animated. The code is of course, right, if I disable the first train, then the second works correctly, if I disable the second as well, then the third works correctly.

I think the second and the third trains inherit some value from the first and that's why they don't work. Unfortunately I'm not very knowledgable with animations. How could I modify the code of the second and the third train so that they worked too?
avatar
phontanka

Posts : 242
Join date : 2012-05-08
Location : Hungary

http://phontanka.wordpress.com

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by leezer3 on Thu Dec 29, 2016 10:33 pm

I'll try and test tomorrow & see what I can find.

My first instinct is that I've overlooked something where multiple cases of TrackFollowerFunction are in use though.

I'm presuming that you've got three separate .animated objects, in which case, please can I have the track positions for each?

Cheers

leezer3

Posts : 969
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by phontanka on Thu Dec 29, 2016 10:44 pm

Yes, they are 3 separate .animated objects. Two of them use the same static object (the Traxx loco), the third is completely different (a Siemens Desiro DMU). If you think it helps, I can send you the route in email. The track positions are:

19950
23500
26355

If it worked, I would add another such train.
avatar
phontanka

Posts : 242
Join date : 2012-05-08
Location : Hungary

http://phontanka.wordpress.com

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by leezer3 on Fri Dec 30, 2016 3:02 pm

Fixed Smile

Primary issue was that the TrackFollowerFunction was being constantly updated, rather than only when the object was visible as per the other functions, which then broke other stuff.
TBQH, we need an option to update the TrackFollowerFunction constantly (For trains which move through the whole route), but will have to think about that one a little more.

Note:
You may see a bug with semi-transparent faces in the current nightly. This is known about & under investigation.

leezer3

Posts : 969
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by leezer3 on Fri Jan 20, 2017 1:25 pm

And now with sound Very Happy



Coming soon to a sim near you. (Not currently in the nightly builds until I get the kinks worked out)

My first implementation of this is very basic- The sound plays looped whilst the object is visible, and has no control over the volume or pitch, and is what's seen here.
You'll also note that the sound radius is IMHO rather too small; It's currently using the default radius for train based sounds (30.0), but allowing the user to change this is on the list before this becomes public.

Really ought to allow the user to change the radius for all sounds too.....

Cheers

leezer3

Posts : 969
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by phontanka on Mon Jan 30, 2017 9:57 pm

Sounds great!
avatar
phontanka

Posts : 242
Join date : 2012-05-08
Location : Hungary

http://phontanka.wordpress.com

Back to top Go down

Re: Animated Objects: Following The Track- Now with SOUND!

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum