edit
After messing with this for a while, what it seems like is that, something was changed in unity. I tried using a bool instead and it works much better. Although I currently have to hold down the gamepad button due to the logic, some progress was made and at least he's going straight out of rolling into running with no problem.
I'm trying to disable the joystick so that after my player does a roll, he will go into an idle animation for a short period and then go back to the blend tree. The blend tree contains idle walk and run animations. At the moment he will roll, transition with "Has Exit Time" into an idle animation (but is still able to slide around if you have the joystick held down) and then transition with "Has Exit Time" to the blend tree.
https://www.youtube.com/watch?v=RVWh-YAQElQ
it's from this tutorial, but I don't know. He never mentions this problem in the video and no one in the comments sections mentions says anything. But basically if you just transition from the roll animation to the blend tree and keep the joystick held down, the animation skips once the roll animation is over. Instead of him just stopping for a second and then allowing the player to move again.
public void OnEnable()
{
if (inputActions == null)
{
inputActions = new PlayerControls();
inputActions.PlayerMovement.Movement.performed += inputActions => movementInput = inputActions.ReadValue<Vector2>();
inputActions.PlayerMovement.Camera.performed += i => cameraInput = i.ReadValue<Vector2>();
if (!animator.GetCurrentAnimatorStateInfo(0).IsName("Idle"))
{
inputActions.PlayerMovement.Movement.performed += inputActions => movementInput = inputActions.ReadValue<Vector2>();
}
}
inputActions.Enable();
}
I've tried disabling the joystick with the code at the bottom, but it just ignores it for some reason.
Related
I'm working on a Unity project, trying to test the UI interaction on the Quest II with hand tracking and ray casting.
I've set up a very basic scene with all the default assets (OVRCameraRig, UIHelper) and added just a button to test the UI interaction.
This is what my scene looks like:
The issue I have is, when I run the scene, the Ray is rotated 90 degrees, and it's attached to the wrist for some reason. I made a video here to show what I mean :
https://www.youtube.com/watch?v=5f12yfpugB8
It's still interacting with the UI though.
Then after watching some online tutorials, I commented out these lines in the HandInputSelector.cs, which was attached to the UIHelper:
void SetActiveController(OVRInput.Controller c)
{
/*
Transform t;
if(c == OVRInput.Controller.LTouch)
{
t = m_CameraRig.leftHandAnchor;
}
else
{
t = m_CameraRig.rightHandAnchor;
}
m_InputModule.rayTransform = t;
*/
}
and instead added a 2nd script to the UI helper, with these lines only:
public OVRHand hand;
public OVRInputModule inputModule;
private void Start()
{
inputModule.rayTransform = hand.PointerPose;
}
Now the ray is at least attached to the correct position, but it still doesn't rotate properly with the hand movement. I made another video of it here :
Now the ray is at least attached to the correct position, but it still doesn't rotate properly with the hand movement. I made another video of it here :
https://youtu.be/q3d0eG2LwY0
My Unity version is 2021.3.1f1
Can someone please tell me what I'm doing wrong?
There is a simple task, on click to play the animation, first forward, then backward. I had such a situation that when the clicks are continuous, everything works as it should, but it is worth making a pause between the next click and there is a delay during playback, which feels like exactly the same time while I was waiting. I thought it might be worth resetting Animator-> enabled = false, but then the animation loses its current state and you have to return to the beginning. Here's a piece of code:
if(_currentState == State.Forward)
{
_animator.SetFloat ("Direction", 1);
_animator.Play(clip.name, 0);
}
else
{
_animator.SetFloat ("Direction", -1);
_animator.Play(clip.name, 0);
}
Thanks for any help
If you used arrows to connect the animations for each other:
Select the arrows which connect the animations for each other
Turn (Has exit time) off
I'm very confused, I try to play animation when hitting a certain object, the hit is detected correctly (the attempt debug) and after that I try to play animation that exists on the object (via the Animator)
yet it tells me Animator does not have an AnimatorController and wont play the animation. Clearly there is an AnimatorController, and he is in fact working correctly:
my code:
if (d.name == "furnacedef")
{
Debug.Log("attempt");
Animator b= d.model.gameObject.GetComponent<Animator>();
b.Play("burning");
}
I'm designing a typeracer game in unity where the player is in an athletics 100m sprint and the faster they type, the faster the character runs.
I'm just wondering should I be aiming to get an animation that completes between every correct letter entered or working out an algorithm that speeds up, slows down and pauses the animation depending on whether the letter is correct.
Has anyone had any experience with something like this before?
Also, being quite new to unity i'm just using the standard assets with Ethan as my model, is this the right thing to be doing here?
Original Thoughts
You could have it so that every correct character type speeds up the animation of the character and slowly ticks down per millisecond that passes (i.e slowing down if you aren't typing). Then when the user enters a wrong character the animation gets increasingly slower (1/10 of the previous time every time (?)).
Solution
In Unity, working with timing is a little difficult, my class and I had issues with it this year. The best solution we found is working within the FixedUpdate loop itself, as this is run on a more concise time frame than just Update.
Example
For my solution (and what we all ended up doing) was to update the time in FixedUpdate and use it in Update
void FixedUpdate() {
if (timer >= 12f) stopped = true;
if (!stopped) timerDT = updateTimer(Time.deltaTime);
}
If the timer variable is greater than 12 (seconds) then stop movement.
If not stopped, continue updating and adding to the timer, as well as giving the frame time back to timerDT
void Update() {
this.transform.translate(velocity * timerDT);
}
This will run and update the game object attached based on its velocity and the time frame given in FixedUpdate
For you, I would have the script save the animation controller as a variable in the script:
Controller animation = {animation controller};
Note: Don't remember what needs to go here, but I'm pretty sure it's the controller
Then you can change the animation like so:
void Update() {
update_animation(timerDT, anim_speed);
}
void FixedUpdate() {
timerDT = updateTimer(Time.deltaTime);
if (timerDT - oldDT > 0.1) {
oldDT = timerDT;
anim_speed = anim_speed / 0.1; // for decreasing speed
}
}
void update_animation(float deltatime, float speed) {
animation["run"].speed = anim_speed;
}
I am building a game where the player runs on a path. When the player triggers a collider, 2 enemy objects will spawn.
What I want is when the first collider trigger has been entered, I want the second collider, which is at a certain distance from the first collider, to get disabled for a certain time. How to achieve this?
If you'd like to disable the colliders so they won't hit or rebound off the wall, for example, then you can change your collider's "isTrigger" variable to true, to change it into a trigger volume instead of a solid collider. This has the effect of disabling it - in that it won't cause other objects to stop or rebound if they hit it.
For example:
function Update() {
if (Input.GetKeyDown(KeyCode.X)) {
collider.isTrigger = true;
}
}
Note that things like MouseOver still work.
If you want to disable that completely, you can try collider.enabled = false. I'm not sure if that works or not. If it doesn't, you can always scale down your collider:
var myOldSize:Vector3;
function DisableBoxCollider(myCollider:BoxCollider)
{
//actually just resizes it
myOldSize=myCollider.size;
myCollider.size=Vector3(0,0,0);
}
function EnableBoxCollider(myCollider:BoxCollider)
{
if(myOldSize!=Vector3(0,0,0))
myCollider.size=myOldSize;
}
You can use the above code to integrate it in your own project. I'm not going to spill out all of the code for you because else we'd miss the point of learning to program and post on Stackoverflow in general. But it should help you to get on your way. Try and play some with the code, and if you have questions, get back here and ask them, providing the question with some code to show what you have tried.