Spritekit : SKAction : timing - sprite-kit

I would like to know when you create a SKAction, you can define SKAction.timingMode and SKAction.timingFunction
both or you have to choose one of them only ?
Thank you

You can do neither, both, one, or the other.
For timingMode, the default value is linear.
For timingFunction, the default value is, well, nothing.
If a timing function is provided, after the normal timing mode is applied, the result is sent to the timing function.
https://developer.apple.com/documentation/spritekit/skaction

Related

Can I change a block parameter using another block for conditional execution?

I'm wondering whether it is possible to change a block parameter in Simulink (or the value of one saved as a variable) using a different block to enable conditional execution. What I would like to do is have a certain block parameter (in this case, Counter) run during the simulation with an initial value, and have it change to a different value if a certain condition is satisfied.
Ultimately, what I would like to get out of this is to get a Counter block to stop running upon the satisfaction of that condition.
I'm pretty new to Simulink, but I'll detail some of the stuff I've tried so far:
Dashboard switches (Slider, Knob etc.) - I know they're used to
change tunable parameters of blocks, but they cannot be linked to
other blocked and can be only be controlled manually.
Matlab Function block - didn't seem to work, I'm obviously missing something.
Is it maybe possible to disable a certain block/link when that condition is met? That would be a straight forward approach, but I'm not sure it can be implemented in Simulink. Any help would be appreciated!
So to meet your ultimate goal have you considered to place your counter in an enabled subsytem?
Whenever the requirements are met to stop the counter you simply disable the subsystem and the counter will stop.
On the output port of that enabled subsystem you will have the options to preserve the last value or reset it to certain one.

How to stop Parameter variaton experiment at certain variable value instead of time

I am running a parameter variation experiment and would like to be able to stop at a variable value instead of at at specified time. In my simulation I have variable that counts whenever an agent passes through my zink. The variable is called Loads. I would like to stop the parameter variation experiment when Loads=16.
I have tried the "additional experiment stop condition", but can't seem to get it right.
https://imgur.com/a/zD2qTfc
You are mixing up 2 things, I think. You want to stop an individual simulation run when something in the model happens. You can easily do that using this code in your actual model (not in the experiment properties):
if (loads==16) getEngine().stop();
What you did was to define when the parameter variation experiment should stop. However, that condition is never satisfied (and it sounds like you don't want that).

Maya Plugin attribute validation

I am trying to validate my custom MPxEmitterNode attributes.
I have force_min and force_max attributes that are double3 typed in maya parlance, basically two objects containing double[3] data.
I want to ensure the force_min is less than force_max for each of its 3 components. I'd like to do this by just swapping the min and max around if someone enters a value on the attribute in the attribute editor, or calls mels setAttr for those attributes, which then fails the "min < max" check.
I have tried setting up ATTRIBUTE_AFFECTS relationships between force_min, force_max and their individual component x,y,z objects. That seems to cause a cyclic issue leading to Maya crashing. I have also tried editing the custom compute function for the derived MPxEmitterNode, so it sets the force_min and force_max values to swap. The force_* attributes are seemingly never computed in this case.
Any help would be much appreciated.
Generally the 'Maya' way to do this would be to let the output look wrong if the min and max are set incorrectly. You don't know who is going to set those attributes -- it could be as connection or a script, and it could even get reset in between frames of an animation -- and so it's better to let the dag evaluation flow through even if the result is nonsense. It's like setting a radius of zero on a sphere node --it's 'correct' even thought it's wrong.
You can however swap the values inside your compute() method to get the same effect as swapping the values without resetting the plug values themselves. Setting an input plug from inside compute is a bad idea, because it introduces a loop into the flow of the dag evaluation. Dag nodes must be acyclical (that's the "a" in dag: Directed Acyclic Graph)

Method for Back button not working when Time.TimeScale=0

I have written below code for Back button event.
void Update()
{
if (Input.GetKey(KeyCode.Escape))
{
SceneManager.LoadScene("PreviousLevel");
}
}
In almost all cases this is fine. But I have found a small issue. When the user pauses the game, this doesn't work. When the user pauses the game, I do Time.timeScale=0. Initially, I gave a thought of modifying pause method and instead of doing Time.timeScale=0, use a bool variable and modify other pause logic accordingly. But then I also realized that I have over 14 co-routines whose logic is heavily dependent on Time.timeScale and modifying those will take a lot of time. They are heavily dependent on time.timeScale.
I wanted to know, is there any other method where I can write back button logic and which is not dependent on Time.timeScale.
It should work, input polling in Unity is not dependent on the time scale.
Try by inserting a Debug.Log inside the condition, and you should see it in the console.
Watch out if you put the if inside FixedUpdate and not Update: in that case it won't work since FixedUpdate is completely skipped when time scale is 0.
However, if you want a "dirty" trick, you can slow the timescale to a very low number, without using 0, i.e.: 10e-8. But use it with a lot of care, since it can lead to unwanted behaviour.
Input is dependent on time scale: GetButton() works normally but GetAxis() works inconsistently, for example getting mouse movement with GetAxis() works as expected, but getting Horizontal and Vertical returns 0 when timeScale is 0. You can get around this by using Input.GetAxisRaw().
It should also be noted that any axis also counts as a button, so you can also use GetButton() on those but the return value will be bool instead of float.

Difference btw. sendmessage and setting Value

What is the difference between those two methods? Why should i prefer one?
1)
GameObject.FindGameObjectWithTag("").GetComponent<Rocket>().active = true;
2)
GameObject.FindGameObjectWithTag("").GetComponent<Rocket>().SendMessage("setActive");
thanks!
Sending a message searches through all the components of the gameObject and invokes any function that has the same name as the message. Not a 100% sure but Im sure this uses reflection which is generally considered slow.
SetActive() or the active variable set the gameObject as active or not. If its not active it wont render in the scene and vice versa.
First of all it seems there are several inconsistencies with your code above:
1) Components (and MonoBehavior) don't have an active property (active belongs to GameObject), so the first line of code shouldn't compile. In addition the most recente version of unity don't have active anymore, it's substitued with activeSelf and activeInHierarchy.
And btw, both activeSelf and activeInHierarchy are read only, so you can't assing directly a value to them. For changing their value use SetActive method.
2)
The second line of code shouldn't work either (unless Unity does some magic behind the scenes) because SetActive methods belong to GameObject and not to your Rocket Component.
Now, I suppose your question was the difference between:
gameObject.SetActive(true);
and
gameObject.SendMessage("SetActive",true);
The result is the same, but in the second way Unity3D will use reflection to find the proper method to be called, if any. Reflection has an heavy impact on performance, so I suggest you to avoid it as much as possible.