Animated Objects: Following The Track- Now with SOUND!
+5
Quork
Phonteus Nevolius
Dexter
phontanka
leezer3
9 posters
Page 1 of 2
Page 1 of 2 • 1, 2
Animated Objects: Following The Track- Now with SOUND!
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:
Limitations:
Finally, the video:
Cheers
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
Finally, the video:
Cheers
Last edited by leezer3 on Fri Jan 20, 2017 2:27 pm; edited 1 time in total
Re: Animated Objects: Following The Track- Now with SOUND!
For reference, this is the code used in the animation above:
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
- 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
Re: Animated Objects: Following The Track- Now with SOUND!
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!
Re: Animated Objects: Following The Track- Now with SOUND!
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
Here's the Siemens Desiro I used in the videos: https://dl.dropboxusercontent.com/u/51947703/BVE/Desiro-TrackFollowerFunction.7z
Re: Animated Objects: Following The Track- Now with SOUND!
This is a somewhat hacky solution to your problem:
A breakdown of the function:
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]]
A breakdown of the function:
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.if[value == 0, value + 1000, if[value < 0, value, value - 10 * delta]]
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]]
Re: Animated Objects: Following The Track- Now with SOUND!
Cool, thanks! I'll give it a try right now!
Re: Animated Objects: Following The Track- Now with SOUND!
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?
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?
Re: Animated Objects: Following The Track- Now with SOUND!
Braking smoothly will get complex fast
This is a three speed-stepped formula (1000m to 100m, 100m to 50m and 50m to 0m)
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:
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 ]]]]
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]
Re: Animated Objects: Following The Track- Now with SOUND!
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.
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.
Re: Animated Objects: Following The Track- Now with SOUND!
Sure
Just requires another if condition.
Using the first function for a little clarity, hopefully you should be able to see the difference:
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
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
Re: Animated Objects: Following The Track- Now with SOUND!
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:
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]]
Re: Animated Objects: Following The Track- Now with SOUND!
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.
Re: Animated Objects: Following The Track- Now with SOUND!
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.....
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:
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
This will come at some stage, but the sound triggering system is an absolute mess.
Improvise?
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
This will come at some stage, but the sound triggering system is an absolute mess.
Improvise?
Re: Animated Objects: Following The Track- Now with SOUND!
I like this! *thinks about a couple of hours tomorrow evening*
Re: Animated Objects: Following The Track- Now with SOUND!
I would like to ask for some help. I'm updating a route and I've added three trackfollower trains with the following code:
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?
- 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?
Re: Animated Objects: Following The Track- Now with SOUND!
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
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
Re: Animated Objects: Following The Track- Now with SOUND!
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.
19950
23500
26355
If it worked, I would add another such train.
Re: Animated Objects: Following The Track- Now with SOUND!
Fixed
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.
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.
Re: Animated Objects: Following The Track- Now with SOUND!
And now with sound
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
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
Re: Animated Objects: Following The Track- Now with SOUND!
Chris, is sound support already included in current builds? And if yes, can you give me a hint about how to use it?
Re: Animated Objects: Following The Track- Now with SOUND!
Ah, rats.....
Not available just at the minute, but will take another dig at them hopefully before the end of the week.
This one has slightly got shunted to the side of my plate.
The basic looped sound functions just fine, but I hit a few bumps with getting pitch / volume alterations working OK.
Similarly, after a little fiddling, it was clear that this needed radius and volume setting by default, and hence a new sound 'animation' format, as lumping them all into an [Object] statement in an animated file really didn't work out well.
In this case, XML doesn't work well either, so I think it's going to end up with something a little similar to the animated format.
Watch this space :S
Not available just at the minute, but will take another dig at them hopefully before the end of the week.
This one has slightly got shunted to the side of my plate.
The basic looped sound functions just fine, but I hit a few bumps with getting pitch / volume alterations working OK.
Similarly, after a little fiddling, it was clear that this needed radius and volume setting by default, and hence a new sound 'animation' format, as lumping them all into an [Object] statement in an animated file really didn't work out well.
In this case, XML doesn't work well either, so I think it's going to end up with something a little similar to the animated format.
Watch this space :S
Re: Animated Objects: Following The Track- Now with SOUND!
OT: Cursing "ah, rats" is particularily hilarious considering Phonteus' avatar pic =D
Quork- Posts : 1438
Join date : 2012-05-05
Age : 33
Location : Hofheim a.T., Hessen (Hesse), European Union
Re: Animated Objects: Following The Track- Now with SOUND!
It's not that important, at the moment I'm happy with a simple looped sound.
Quork: yeah, now that you mention it! But actually it's a mouse from the Hungarian animated film, Cat City, its name is Grabowski.
Quork: yeah, now that you mention it! But actually it's a mouse from the Hungarian animated film, Cat City, its name is Grabowski.
Page 1 of 2 • 1, 2
Similar topics
» .animated sound limitations?
» Objects in an animated container disappear in Routeviewer and OpenBVE after the insertion point of the .animated file
» Is it possible to add objects to a track?
» .animated sound (StateChangeSound)
» .animated sound
» Objects in an animated container disappear in Routeviewer and OpenBVE after the insertion point of the .animated file
» Is it possible to add objects to a track?
» .animated sound (StateChangeSound)
» .animated sound
Page 1 of 2
Permissions in this forum:
You cannot reply to topics in this forum