Animation code - assistance needed
5 posters
Page 1 of 1
Animation code - assistance needed
Hi All,
Im wondering if anyone can help me with a bit of coding? Me, Steve and Mick are still working hard on the airedale line, but theres something i am struggling with, and thats the coding for "moving objects".
I have the code for a object to move from A to B, but im wanting to know the code for "when player train is X meters away" i have tried changing numbers and figures but im having no luck, it may be something i have overlooked, or maybe something i am yet to try, but im hoping to get to the bottom of it before i can move along to the next stage of the route.
For the class 195 thats arriving at BFS, i am using this code.
can someone who knows animation coding, please explain to me which bit would be the "when player train is X meters away" part?
I know a while back someone made a level crossing that lifted / lowered upon certain distance the player train was, but i am scratching my head at who created that bit of code.
Im wondering if anyone can help me with a bit of coding? Me, Steve and Mick are still working hard on the airedale line, but theres something i am struggling with, and thats the coding for "moving objects".
I have the code for a object to move from A to B, but im wanting to know the code for "when player train is X meters away" i have tried changing numbers and figures but im having no luck, it may be something i have overlooked, or maybe something i am yet to try, but im hoping to get to the bottom of it before i can move along to the next stage of the route.
For the class 195 thats arriving at BFS, i am using this code.
- Code:
StateFunction = if[value + delta > 100, -1,0]
TrackFollowerFunction = if[value == 0, value + 180, if[trackdistance > -150,if[value < 0, value, value - 5 * delta], value]]
can someone who knows animation coding, please explain to me which bit would be the "when player train is X meters away" part?
I know a while back someone made a level crossing that lifted / lowered upon certain distance the player train was, but i am scratching my head at who created that bit of code.
Last edited by Quork on Sat Feb 08, 2020 5:52 pm; edited 1 time in total (Reason for editing : admin edit - more meaningful topic title)
mrknowitall- Posts : 824
Join date : 2011-07-09
Age : 32
Location : W. Yorkshire
Re: Animation code - assistance needed
Some time back I suggested that perhaps a "cook book" with a few animated code examples might be useful? My understanding is too limited to produce such a thing, unfortunately.
I really struggle with animated coding, not really understanding the mechanics or syntax of the whole thing. And don't even start on boolean functions.
I made a both a lifting crossing barrier and a swing-gated crossing which open and shut when the player train is at a specified distance from the gates. I freely admit I "borrowed" the function line after studying another dev's item (could've been one of Dexter's?) to see how it was done.
Good luck with that, Ben, I'm sure someone can help, I've had help myself in the past from Chris, if he doesn't know nobody does!
I really struggle with animated coding, not really understanding the mechanics or syntax of the whole thing. And don't even start on boolean functions.
I made a both a lifting crossing barrier and a swing-gated crossing which open and shut when the player train is at a specified distance from the gates. I freely admit I "borrowed" the function line after studying another dev's item (could've been one of Dexter's?) to see how it was done.
Good luck with that, Ben, I'm sure someone can help, I've had help myself in the past from Chris, if he doesn't know nobody does!
Re: Animation code - assistance needed
Who, me
Let's take this function step by step.
We first evaluate the following clause:
if[value == 0
Simple really- If the *current* value is zero, then return the first option, if not, return the second.
When our object is first shown by the renderer, this value will always be zero.
The first option is again simple:
value + 180
This adds 180 to the value. Now, the next time the funciton is evaluated (in other words, the next frame so immediately), it'll return the second option, which is the following:
if[trackdistance > -150,if[value < 0, value, value - 5 * delta], value]
First, note that here we've got another nested if clause, not just a simple value.
This will be evaluated in exactly the same way as the first above, so let's go onwards:
if[ trackdistance > -150
If our trackdistance (The distance to the player train) is greater than -150m, it will return the first option. Otherwise it'll return the second.
Remember that the track distance in this case is a signed number; When the train is approaching the object, it will return a negative number, and once passed it will return a positive number.
When the object is first shown by the renderer, trackdistance will be approximately your viewing distance, and as the train approaches this number will go downwards
This means it'll return the second option until your train is within the 150m distance:
value
This just returns the previous value (180)
When however we get within 150m, it evaluates yet another nested if statement:
if[value < 0, value, value - 5 * delta]
Again, relatively simple:
if[value < 0
If our value is less than 0, return the second option. Otherwise, return the first.
As we've just moved the value to 180, it will return the second.
Our second option is fortunately simple:
value - 5 * delta
Going back to secondary school maths, the MULTIPLICATION is done before the SUBTRACTION.
We therefore take the delta, which is the time elapsed for the previous frame in seconds (likely to be ~0.03 or less) and multiply it by 5 to give the total distance moved by the object this frame, so something about 10cm or so.
This is then subtracted from the previous value to give the new position of the object.
The final part of this is simplicity itself, and is returned when our value evaluates to less than zero-
value
The last value- Our object stops moving!
Confused yet?
Let's take this function step by step.
We first evaluate the following clause:
if[value == 0
Simple really- If the *current* value is zero, then return the first option, if not, return the second.
When our object is first shown by the renderer, this value will always be zero.
The first option is again simple:
value + 180
This adds 180 to the value. Now, the next time the funciton is evaluated (in other words, the next frame so immediately), it'll return the second option, which is the following:
if[trackdistance > -150,if[value < 0, value, value - 5 * delta], value]
First, note that here we've got another nested if clause, not just a simple value.
This will be evaluated in exactly the same way as the first above, so let's go onwards:
if[ trackdistance > -150
If our trackdistance (The distance to the player train) is greater than -150m, it will return the first option. Otherwise it'll return the second.
Remember that the track distance in this case is a signed number; When the train is approaching the object, it will return a negative number, and once passed it will return a positive number.
When the object is first shown by the renderer, trackdistance will be approximately your viewing distance, and as the train approaches this number will go downwards
This means it'll return the second option until your train is within the 150m distance:
value
This just returns the previous value (180)
When however we get within 150m, it evaluates yet another nested if statement:
if[value < 0, value, value - 5 * delta]
Again, relatively simple:
if[value < 0
If our value is less than 0, return the second option. Otherwise, return the first.
As we've just moved the value to 180, it will return the second.
Our second option is fortunately simple:
value - 5 * delta
Going back to secondary school maths, the MULTIPLICATION is done before the SUBTRACTION.
We therefore take the delta, which is the time elapsed for the previous frame in seconds (likely to be ~0.03 or less) and multiply it by 5 to give the total distance moved by the object this frame, so something about 10cm or so.
This is then subtracted from the previous value to give the new position of the object.
The final part of this is simplicity itself, and is returned when our value evaluates to less than zero-
value
The last value- Our object stops moving!
Confused yet?
Re: Animation code - assistance needed
I wish there was a like button here, I really appreciate such explanations of .animated code.
mrknowitall- Posts : 824
Join date : 2011-07-09
Age : 32
Location : W. Yorkshire
Re: Animation code - assistance needed
But there is! =D On the right hand side of the post you can see a tiny "+" and a tiny "-". The "+" is a like. It's a rather basic system, but that's how the reputation value you can see under the avatar of every poster is calculated.Phonteus Nevolius wrote:I wish there was a like button here, I really appreciate such explanations of .animated code.
Quork- Posts : 1438
Join date : 2012-05-05
Age : 33
Location : Hofheim a.T., Hessen (Hesse), European Union
Re: Animation code - assistance needed
Oh, never noticed that... Anyway, I've only been using this forum for 8 years... Thanks!
Similar topics
» Building a Route Based on the Staten Island Railway Integrated into the NYC Subway System (Download Update 10/24/2023)
» Portal code modification
» Delay code for RotateFunction?
» Animation formula brainpicking...
» Short term work - What should happen to managed content?
» Portal code modification
» Delay code for RotateFunction?
» Animation formula brainpicking...
» Short term work - What should happen to managed content?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum