|
Post by Legend on May 2, 2018 19:21:37 GMT
do you know of an easy way to get the current state from a different script?
ineed a couple views (player and minion) to make sure that the state is reset when i hit a button...that button doesnt have the clickable component and i dont want it to as it is a button and not going to do anything with the clickable script....
so far ive only thought about creating a variable to the the controller from each script then setting the statemachine to public then creating another method within clicktoplay to call reset or making reset public as well whichever....thoughtS?
|
|
|
Post by Legend on May 2, 2018 20:01:40 GMT
I almost got it working
but it causes the layoutcards method to loop - the tweener doesnt go null so it cant return so its just looping - wonder if its because im disabling the object parent before the card can move backto the location and it gets stuck or something - weird thing is i can see the card in its proper location when i re enable it...havent dealt with tween to much so going to have to dig into it a bit.
|
|
|
Post by Legend on May 3, 2018 13:04:55 GMT
not sure if its the best way to fix it but it works stuck it in the while loop basically the tweener kept on running cause i closed the panel instead of clicking off while in confirmorcancelstate so that pended click was going to the panel close and for whatever reason (guessing because it was getting disabled and im making the card go to that panel)
if (!isPanelOpen) tweener = null;
|
|
|
Post by Admin on May 3, 2018 14:52:10 GMT
You "can" always make the statemachine and its states "public" in order to allow other scripts the opportunity to modify them. However, I would personally try to avoid it. It is good to keep the internals of a system private because it helps to avoid spaghetti code - such as if you modify logic in one place it has an affect on code in many other places and it becomes really difficult to understand. Ideally, once you have entered an input flow, the flow itself should know every way of how to complete or cancel its flow. This is also important because you want to be able to ensure that a flow is properly canceled. For example, if you had a card in preview mode and wanted it to animate back to the hand before the flow could cancel.
This might mean that a click on a button doesn't do the "normal" action when triggered because the input flow needs to be canceled first. Being able to support this conditional activation is a good thing, because if you always allow buttons to perform their actions regardless of game state then you are likely to put the game in unexpected scenarios that can lead to difficult to solve bugs.
The tweener is basically an animation controller. It keeps track of the desired key-frames for an animation and upon completion will destroy itself.
Regardless, I'm glad to hear you have something working. Good luck!
|
|
|
Post by Legend on May 3, 2018 19:20:49 GMT
thanks for the reply!
Ya my thoughts about which is why i was hesitent and tried to do it the other way which i eventually got working.
the tweener i saw that in the tweener complete event thing in the code which would make it null im guess so that makes sense
another question i got from all this working on some animation - - im looking at doing a jump instead of a simple move to and from- adding a little pizaz - as far as the current tween scripts dont have a method for this. and i believe modifying - this is for the minions not the card
I was thinking to add a movetowithjump function and see what i need to change for that
on closer inspection - it appears to be confusing - did you write this code or did you get it from a source in which it might have further methods to use like a jump one or something?
if not all good - ive been looking at dotween as an alternate and i can use that dojump method that appears to be exactly what i need
thanks again! legend
|
|
|
Post by Legend on May 3, 2018 19:46:08 GMT
O wow k that wont work right off the bat with dotween cause how the game was made is the Z is up and down and the X is left and right instead of the Y being up and down and the X being left and right
so the Z and the Y are swapped. wellllll bullox
|
|
|
Post by Admin on May 4, 2018 13:51:07 GMT
I wrote the animation code as well - if you look through the history of my blog you will see a mini series of posts as they are made. The tweener uses math curves to interpolate between two fixed values as time progresses. A "jump" requires you to interpolate between three points. I will sometimes build jumps by assembling multiple tweeners such as one for moving an object along the horizontal plane and one for moving it on the vertical plane. Check out the Tactics RPG project and see how units will jump when going up stairs.
You could also create your own subclass of the "TransformPositionTweener" as a "JumpTweener" and add an extra field for jump height. After getting the "currentTweenValue" from the OnUpdate function, you could then add a multiple of the jump height to the y-axis based on the "currentTime" field which will range between 0 and 1. So I think something like this would work (haven't tried it though):
float jumpPercent = Mathf.Abs (currentTime - 0.5f) / 0.5f; // provides a new value between 0 and 1 where it will be at 1 at the middle of an animation and 0 at the beginning and end float jumpOffset = jumpPercent * jumpHeight; // where jumpHeight is a value you assign as a field for the jumper tweener currentTweenValue = new Vector3 (currentTweenValue.x, currentTweenValue.y + jumpOffset, currentTweenValue.z);
|
|
|
Post by Admin on May 4, 2018 13:54:36 GMT
Actually, I think that would produce an ugly jump because the jump offset would be linear. After getting the "jumpPercent" you should probably run it through another easing equation so you might use something like this instead:
float jumpOffset = EasingEquations.EaseOutQuad(0, 1, jumpPercent) * jumpHeight;
|
|
|
Post by Legend on May 4, 2018 13:59:49 GMT
awesome thanks! ill play around with this and report back! right off the bat though the jumpoffset will need to be on the Z not on the y value as you reversed the z and y axis jobs but this will give more flexibility then using the DOTween library
|
|
|
Post by Legend on May 4, 2018 15:54:13 GMT
public class TransformJumpTweener : TransformPositionTweener {
public float jumpHeight;
protected override void OnUpdate() { float jumpPercent = Mathf.Abs(currentTime - 0.5f) / 0.5f;
float jumpOffset = EasingEquations.EaseInOutQuad(0, 1, jumpPercent) * jumpHeight;
base.OnUpdate(); var JumpingcurrentTweenValue = new Vector3(currentTweenValue.x, currentTweenValue.y, currentTweenValue.z + jumpOffset);
transform.position = JumpingcurrentTweenValue; } }
thar it iss - doesnt work cause it shoot off to the end x instead and drops down to the targets position playing with it a bit more
|
|
|
Post by Legend on May 4, 2018 19:29:01 GMT
ugh not fond of math
float jumpPercent ;
// where jumpHeight is a value you assign as a field for the jumper tweener if (currentTime < .5) jumpPercent = Mathf.Abs(currentTime) / .5f; else jumpPercent = Mathf.Abs(currentTime) ;
so far - as i can see that the current jumppercent does not drop halfway which was the problem now i can get to .5 havent figured out how to drop the jump yet
|
|
|
Post by Legend on May 4, 2018 19:57:06 GMT
success!
if (currentTime < .5) jumpPercent = Mathf.Abs(currentTime) / .5f; else jumpPercent = Mathf.Abs(currentTime -1f) / .5f ;
|
|
|
Post by Legend on May 5, 2018 2:58:58 GMT
the rest of the code should be pretty much copy paste and tweak - in case anyone else needs help with this
i just pretty much did the same thing as moveto just added a jump height var to the jumpto method
and made the transformJumptweener as you see above with the proper variables
|
|