Hello, i was asked to turn the above code, specifically the part which changes the arms animation into dynamic code. To be more clear, āthis.arms.anim.baseLayer.activeState !== āPistol idleā)ā there shouldnāt be the name of animations. I understand that there need to be a for loop for the animation states just like i did with the weapon models and icons. But i donāt know how i can set bools in the if statement without writing animation names. I canāt figure out what to do, iād appreciate any tips and pointers regarding this issue
@Ronin This is just a thought on how to accomplish this but probably not ideal. What you could do is create an animation state graph with transitions to each state. Each state would be changed by a number and not a name. This will work but the down fall is number one you will have to keep all the numbers referencing states correct as you replace. The other downside would be that your code would not be very readable to others since others would have to refence the state graph parameter to figure out what is happening. Hope this helps. I am sure others will chime in if more ideas come to mind.
my supervisor doesnāt want anything in the script to be hardcoded, thatās the thing. But i donāt understand how i can switch animations without calling their name. This is his exact instructions:
For example, we should not have movement code in the weaponManager or do static controls like this.arms.anim.baseLayer.activeState !== āRifle reloadā instead, we should be able to check activeState == reload and set the current weapon with the weaponType value.
We should be able to check activeState == reload and set the current weapon with the weaponType value.*
If you write the animation names as weaponType + ā-Reloadā it will be dynamic
@Ronin The best I can tell from the snippet above is that there is a decision being made as to if the animation state is not already in the state you want to switch it to. This is logical as you donāt need to switch the animation if it is already in that state. I understand the question about the naming. I really donāt know how you can make it more generic other than just using numbers or something. You could keep an object array of containing each weapon which would include attributes or maybe JSON structure that could be used to pull generic tags from for the names.
I think the goal is to use for example one variable for your weapon and use this variable in your code to switch to the correct weapon and animation. This way your code is dynamic because you donāt have to add a lot of code if you add for example a new weapon. No idea if Iām correct.
Thanks for all the input you offered. I guess iām not the only one who couldnāt understand what my supervisor is asking from me exactly. I also asked my brother who is a programmer for help, his solution wasnāt also what my supervisor wanted to achieve. We decided to skip that part for now, i return here if thereāll be any changes. Thanks a million again
I used this code to switch the animations with a for loop, he said this in response:
This is the issue Iām talking about, you canāt do this with index etc. when the order of those weapons is changed then you will need to fix the code again