leezer3 / OpenBVE

OpenBVE- A free train simulator
http://www.openbve-project.net
280 stars 52 forks source link

[Question] how to easing a trains door speed? #763

Open adfriz opened 2 years ago

adfriz commented 2 years ago

Hello

I wanna know can we use and write easing a speed of any animation like door opening and closing speed.

Because my train door speed is linear if using the command below.

In car1.animated i write this

[object] states = doorR.b3d position = 0, 0, 0.3 TranslateZDirection = 0, 0, -1.3 TranslateZFunction = rightdoors

Usually after rightdoors command i add * 0.5 or / 0.5 to change its speed but the speed still behave linearly.

I also read this doc about easing but i dont know how to write it or even that formula will work on openbve or not. https://docs.microsoft.com/en-us/dotnet/desktop/wpf/graphics-multimedia/easing-functions?view=netframeworkdesktop-4.8

I just want to that door speed using exponential easing for closing and opening, the door also using a same door sound for open and close, the sound is 7 seconds long with first 2 second is warning sound before the door start to close or open, and 5 seconds sound for the door to fully close or open.

leezer3 commented 2 years ago

As you probably know, the opening / closing speed of the train doors is by default determined by the length of the sounds. https://openbve-project.net/documentation_hugo/en/trains/sound_cfg.html

If you want to specifically control the opening / closing speed of the doors, this can be done if the train is converted to XML. I've updated the documentation, as this was missing and it should be visible on the main site shortly.

adfriz commented 2 years ago

Yup i know door speed determined by its sound length.

Wow i dont know how powerfull train.xml is until i read the documentation 😅, its seems not only replace train.cfg also replace sound.cfg, train.txt and ats.cfg into one file, very convenient. Although i havent familiar using xml 😅.

More question.

  1. If the door speed i set in train.xml is less/more than its sound i set in sound.xml, how is the result ? If the door speed is 7 second and door sound is 5 second, is the sound will start playing at 3rd seconds and finished at 7th second same time as the door fully closed ?.

Anyway thanks leezer3

leezer3 commented 2 years ago

That's the idea.

Extending the existing formats is messy and creates as many problems as it solves, hence working on a new one. It's not complete (still requires a train.dat at the minute), but getting there.

Duration: The close time as set via XML is entirely independent of the sound. The sound triggers when the button is pressed and plays to its end.

Kenny-Hui commented 2 years ago

But other than speed, is there like an example code on an animated door that eases on both opening and closing, and what each part is doing?

I've took a look at other trains that eases, but I am still having trouble figuring out what each number means in here

[Object]
States = door\doorL_L.b3d
TranslateZFunction = if[leftdoorstarget==0 < 1.3, Min[0.145 * Sin[leftdoors * 12] - 2.1 * leftdoors + 1.08,0], 0]*0.7

My expected closing door animation is start gradually closing after the warning sound played 2 second. Then gradually stop the movement, leaving ~0.1m gap. Then after a short duration of time, gradually close the rest of the gap.

But I often end making up alot of nested if statement to check the door state (Before I even implement easing)

ginga81 commented 2 years ago

I also have a question. How to create by XML such as these door speed change. I think that his question is the same as these movie. https://www.youtube.com/watch?v=Pp62_f3SRas If we want to use with XML, I think that we have to more easily to create what is change the speed of plug doors and doors when opening and closing.

Kenny-Hui commented 2 years ago

Something like that yeah. I've downloaded some of them to take a look, but it's still a lot of if statement and somewhat tripped me up.

I think the XML only unlink the door speed with sound rather than allowing them to ease/change the speed dynamically though