Parabolic jump animation using javafx - animation

I'm making a simple sidescrolling platformer shooter game using JavaFX. I want a very simple parabolic jump animation for the character. Currently, the character extends StackPane, and it lives on a Scene. I was told to use Interpolator.SPLINE for the jump animation, but it does not seem to be working.
Currently, I have:
public void Jump(){
TranslateTransition translation = new TranslateTransition(Duration.millis(1), this);
translation.interpolatorProperty().set(Interpolator.SPLINE(.1, .1, .7, .7));
translation.play();
}
but it does not seem to move at all. My other animation commands (move left and move right) are working using simple translate transition however. What am I doing wrong with the jump function?

You have 2 problems:
your transition doesn't move anything, you need to set where to move using your interpolator, e.g. translation.setByY(-50);
Duration.millis(1) is 1 millisecond, you can't see anything moving so fast. Try 500
Also, if you want a jump you need to provide return movement as well. Easiest would be to revert current transition by:
translation.setAutoReverse(true);
translation.setCycleCount(2);
Example:
TranslateTransition translation = new TranslateTransition(Duration.millis(500), this);
translation.interpolatorProperty().set(Interpolator.SPLINE(.1, .1, .7, .7));
translation.setByY(-50);
translation.setAutoReverse(true);
translation.setCycleCount(2);
translation.play();

Related

Unity 3D - Dynamically 'slicing' background image

I'm fairly new to Unity and not quite sure how to handle this problem.
I have two images, one has clouds on it (day) and one has stars on it (night). What I want to do is show the clouds in the top of my scene and the stars on the bottom. There is a ground object in the middle of the screen where the player will be walking on, this should be the dividing line between the two images. The ground however is not one straight line but can have height differences.
The "solution" I came up with is to use the ground object(s) to slice the images so it kinda serves as a dividing line. But not sure if this is even possible. Maybe I could do something with 2 different camera's or mask the images somehow.. (Just throwing my own thoughts in here as well) I'll be fumbling around with these things in between and try to keep the topic up to date with what I tried.
I put in an attachment to (hopefully) make it more clear.
Greets,
Lukie
attachment: https://imgur.com/a/lblJXPi
The first solution to my mind was preparing a tileset. If you're not going to design a different section every time. So if you're not going to do a computer design. You can do it yourself by adjusting the size.
You can also dynamically generate the stars with the -y axis of the ground object and the clouds with the + y-axis. You can use instantiate function
Example:
public GameObject clouds;
public GameObject stars;
// Start is called before the first frame update
private void Awake()
{
Instantiate(clouds, new Vector3(this.transform.position.x, this.transform.position.y + 3.625f, this.transform.position.z), Quaternion.identity);
Instantiate(stars, new Vector3(this.transform.position.x, this.transform.position.y - 3.625f, this.transform.position.z), Quaternion.identity);
}
Of course, the background design that you will use here must be sustainable.
Dynamic Background

How should I do this animation or how should I aproach this dilemma?

So, I have a cube and I want to make a game where the cube jumps from a pylon to another and now I am at the point where I want to make the pylon fall if the cube stays on it more than a given amount of time.
I don't want to use physics or rigid body, I am using just transform.position and Raycast to click on the next pylon I want the cube to jump, I want to use animations, so if the cub stays more than a given amount of time on the current pylon, that pylon will fall taking the cube with it.
The problem is that I don't know what to do, where to begin; regarding animations in unity I only know how to do Animation Clips.
I would learn to do other things but I actually have no ideea how to approach this problem, what technique should I use to get the desired outcome, and how?
First you need to detect if the cube is on the pylon.
If it is, then you need to start a timer.
If the timer reaches 0 then the pylon falls.
You can use OnCollisionEnter to Detect if the cube has collided with (landed on) the pylon:
void OnCollisionEnter(Collision col)
{
// Check if it is the cube that has collided.
if (col.gameObject.name == "Player") // Make sure to assign the Player Tag to the cube
{
// Start countdown timer.
}
}
You could start a countdown timer using a coroutine.
You will need to add using System.Collections; at the top of your class.
Call your coroutine using StartCoroutine(MyCoroutine());
IEnumerator MyCoroutine()
{
// Wait for 3 seconds.
yield return new WaitForSeconds(3f);
// Make the pylon fall now.
}
This code will cause the game to wait for 3 seconds before doing something. How you make the pylon fall is up to you, you could use a RigidBody and set isKinematic from true to false as an example, but since you have said you don't want to use physics, you could translate the pylon downwards using Transform.position.
This should get you started.

Unity 3D Kudan "Place Markerless Object" whenever mesh leaves screen?

I´m kinda new to Unity 3D and C#. Also i´m not exactly sure how Kudans arbitrary tracking solution works in detail. I´m currently using the Unity Kudan SDK to build a VR positional tracking solution, atleast i will try it. Now my plan is:
Whenever the mesh is leaving the screen, i want to freeze it´s position and find new feature points (the "place markerless object" button is doing this: Find new feature point and place a mesh).
Once it found new feature points (which should be a matter of milliseconds) it defreezes the position of the mesh and use the new feature points to further alter it´s position.
The "find new feature point" idea is necessary because whenever the mesh and the old feature points are leaving the screen, tracking will get very inaccurate.
I already tried this in SampleApp.cs:
bool VRSignal;
public void Start()
{
//Get Bools from "KudanTracker"
GameObject g = GameObject.Find("Kudan Camera");
KudanTracker bScript = g.GetComponent<KudanTracker>();
bool VRSignal = bScript.ArbiTrackIsTracking();
}
public void Update()
{
if(VRSignal == false)
{
// from the floor placer.
Vector3 floorPosition; // The current position in 3D space of the floor
Quaternion floorOrientation; // The current orientation of the floor in 3D space, relative to the device
_kudanTracker.FloorPlaceGetPose(out floorPosition, out floorOrientation); // Gets the position and orientation of the floor and assigns the referenced Vector3 and Quaternion those values
_kudanTracker.ArbiTrackStart(floorPosition, floorOrientation); // Starts markerless tracking based upon the given floor position and orientations
}
}
But now it won´t track properly track anymore, also i´m pretty sure ArbiTrackIsTracking() won´t be the solution for that because it won´t lose tracking when the mesh left the screen.
Do you have any idea to solve this problem?
if I understand well, you want change position of 3d model with trigger as soon as your 3d model disappear of the screen.
And you are right, ArbiTrackIsTracking() remain true even if the 3d model go out the screen because if you move again your screen around the 3d model, the 3d model will be always tracked.
But if you move too much your smartphone logically the tracking stops.
My idea for your issue is to get the position of your 3d model markerless transform driver, because the 3d model moves in function the position and orientation of your smartphone to track.
So you can take the position of the moment where your 3d model begin to be tracked.
Then you give a value who will correspond to the difference of first and last position saved.
And if this difference is get, you stop the tracking with arbitrack stop.
if you have another question you can ask on my twitter account #ModeLolito I could answer faster.
And you can watch my youtube channel to see my works on kudan
https://www.youtube.com/user/modelisationLolito

Unity - How To Animate UI Text Smoothly?

I just wanted to know how do you transition a UnityEngine.UI from one position to another smoothly?
My current code is this:
GameObject rank1;
GameObject rankSlot1;
rank1 = GameObject.Find("Rank1");
rankSlot1 = GameObject.Find("RankSlot1");
rank1.transform.position = new Vector3(Mathf.Lerp (rank1.transform.position.x, rankSlot1.transform.position.x, 0.1f), rankSlot1.transform.position.y, 0);
But it seems like the Mathf.Lerp doesn't work :/
Thanks!
EDIT: All these gameobjects do have Rect Transform as they are a children of Canvas
It depends where do you use Lerp ? Are you calling it once ? or in Update(). Calling in update with correct parameters should work.
Beside Lerp, you can use Animator component with position curves to move from one point to another.
There is another option to use LeanTween plugin, it is a free plugin on asset store.
LeanTween.move(gameObject, yourFinalPosition, duration);
If using an animator you get access to the animation curves so you can get really nice controlled animations
Tricky part is if you are wanting to use 'apply root motion' (have the animations start where they are instead of fixed positions) you need to apply it to something that is considered ROOT:
- create an empty gameobject - with a normal transform
- parent the canvas with text to this new gameobject
- apply the animations to the gameobject transform ( not the UI rectTransform)
- on the animation in the inspector you should now be able to click on the 'generate root motion curves' and also select the 'apply root motion' check box for the Animator
hope this helps,, took a few hours to get working :) I used this to float up enemy damage text displays

Basic, Frame by Frame Sprite animation using Animator class

I have a simple sprite sheet that I'm using in a Unity project:
It has frames for walking and standing in each of four directions. I've cut the image up using Unity's Sprite Editor and made a separate Animation object for each series, all of which fit neatly into a single animation controller:
I've added the animation controller to an Animator component on a GameObject in my scene. This is where I start running into trouble. I can't for the life of me figure out how to change between the animations in my code.
You are not supposed to create the connections between your animations in a script. What you do is you create the connections in the Animator and set up variables for if you are standing or walking and in which direction you are going. Then you just edit these variables in a script and the Animator takes care of chosing the right animation.
This video shows it in action: Example
(you see the connections and in the bottom left the variables he set up)
Quick google of "mechanim 2d tutorial" gives you: Tutorial
edit:
Too long for a comment :)
Basically what i would do is create 2 variables, one bool named "Standing" and one Integer named "Direction". Then you make one connection from AnyState to every other state you have(Rightclick on AnyState to make the transitions). Maybe order them in a circle around AnyState.
After this, click on the connections and in the Inspector set the conditions by chosing "Standing", then add one more and set it to "Direction" "Equals" and the number for the direction.
Then in your script somewhere in your Update function you might have something like:
private readonly int UP = 0;
...
if(speed.magnitude > 0.0f)
Animator.SetBool("Standing", false);
else
Animator.SetBool("Standing", true);
if( Condition for walking up? )
Animator.SetInteger("Direction", UP);
if( Condition for walking down? )
Animator.SetInteger("Direction", DOWN);
...
this might not work directly, but you get the idea. You might want to use a switch for the direction depending on how you set it up.
Why even use code? Just hook it all up in the Animator using parameters and just change the parameters as needed.
The Animator.CrossFade function will achieve the desired results:
C#:
Animator animator = this.GetComponent<Animator>();
animator.CrossFade("WizzyWalkDown", 0);
It may seem a little excessive, or counter-intuitive, but remember that the AnimationController class was built to make transitions between animations easy. It can still very much be used for simpler animation types like this, though!

Resources