I've got a jump animation but i forgot to make a seperate 'falling' animation (and i've lost the original blender files so I can't go back and make one). At the moment, my character jumps and then the run aniamtion starts as soon as the jump is complete, so it starts running mid air.
What's the best way of solving this?
Can I pause the animation mid way through the jump?
I'm using c#.
Thanks!
You can pause the animation when the player is in the air with Animator.enabled = false; or Animator.StopPlayback(); then detect when the player is touching the floor with collider and enable your animation again.
Related
So in my character movement script I'm trying to play the jump audio I have when my character jumps. This works just fine but a problem I have is that:
In my game when I hit a enemy object my character movement stops and a menu comes up. The issue here is sometimes I hit a enemy object whilst still in the air. This causes my jump sound to bug out and constantly replay really quickly creating a really awful noise since when i hit the object my character stops moving in the air.
Just to be clear the issue isnt with hitting the actual enemy the problem is that I have the jump sound to play when I jump and since I die on top of the enemy I assume the jump sounds keep repeating itself because I never actually exit the jump because on death all character movement stops so I'm still stuck on top of the hurdle so the jump never really ends and then a menu comes onto the screen.
my current code for the jumping is:
if (controller.isGrounded)
{
// Jumping for pc
verticalVelocity = -gravity * Time.deltaTime;
if (Input.GetKeyDown(KeyCode.Space))
{
verticalVelocity = jumpForce;
animator.SetBool("is_in_air", true);
jump.Play();
}
}
What would i have to do in here in order to only make the jump.Play(); only play once and not keep repeating itself and making that horrible noise when I die ontop of an enemy object?
Edit: I guess a potential fix could be to mute just the jump sound clip or audiosource once the death menu pops up.
I have this structure of animations:https://i.stack.imgur.com/Rv0fq.png
The idle state runs in a loop until the user presses "space",then parameter named "Jump" becomes true and the transition between idle and Jump becomes active.But before it becomes active user has to wait for "idle" to finish.How can i make it so when user presses space,idle automatically stops and transits to Jump? I tried making 'animation' stop like this:
if(Input.GetKeyDown("space")){
anim.Stop();
animator.SetBool("Jump",true);
}
But it didn't work.
Ok, I warn you the jump is not that easy.
You will need to know if the player is on ground if you don't want your player to be able to jump in the air and many other things.
Anyway to your question.
To avoid exit time on animation you should uncheck the "Has exit time" value on the animator arrow between an animation and the other one.
Your current code just stop the animator but that's not what you really want... you want it to return to Idle.
The best thing you can do is:
- From "Any state" to "Jump" (you should create a blend tree between Jump and Fall)--->in the arrow uncheck "Has exit time" and set up a new Bool "JumpBool" (for example).
From "Entry" to "Idle"
From "Jump" to "Idle" when "JumpBool" is false.
In your code:
if(Input.GetKeyDown("space") && !OnGround()){
animator.SetBool("JumpBool",true);
}
(you should create your OnGround method).
else if(OnGround()){
animator.SetBool("JumpBool",false);
}
Of course this is almost pseudo-code. Like I said you should create a BlendTree for Jump and Fall where you should be able to tell if you need to play the jump animation of just the fall animation (maybe with a float depending on your corrent rigidbody .velocity.y speed).
I am currently working on a 3D Unity game in which you control a block through a labyrinth made out of blocks and have to avoid spikes, moving enemys and other traps.
Here a picture how it looks at the moment ( you are the blue cube and have to avoid the moving pink ones ):
The problem now is, that when I move along a wall, the player gets stuck and stops moving until I move in the other direction again (every part of the wall is as big as the player because I am generating it from an image).
I already tried everything with Physics materials and friction but it does not get better :(.
The problem is that your BoxCollider of the player is probably getting stuck on the edges between two of the wall colliders. Consider "smoothing" the edges of the collider a bit so the player wont get stuck.
The default collision detection mode in Colliders is Descrete, it might jump through a small gap occasionally, you could set the players collider to CollisionDetectionMode.Continuous it will prevent the overshoot.
Try decreasing the Default Contact Offset in Edit/Project Settings/Physics
Changing it from 0.01 to 0.0001 worked for me
Source
I downloaded 2 animations from Mixamo called Idle and Walk_Forward. I created my controller with blend tree and it worked fine. But the problem is when I press W button, the character only move a short distance then back up to the orginal place where he start "Idle". Someone told me to download animation with "In place" option. So I tried then had another problem: The character just play animation but not move forward. About my component on character, I created RigidBody with Use Gravity, and the animation and character is humanoid type. How can I make those animations work ?
If you are using an animation which animates in place then you'll have to add a characterController to make you're character actually move. The animation will only make it look like you'r player is moving. Here is an example of how to move your character.
Implement import of model settings and set "Animation Type as humanoid" in the Rig tab. Then press Apply. Now your animation would not repeat.
I've been stuck on this the last few days so I'm hoping you guys can help.
I'm making a 2D game and I want my character to slip, fall backwards, and hit his head when he tries to run on ice for too long.
My goal is to have it where if you keep holding the run button long enough on ice, he will slip backwards and damage himself.
I'm using playmaker but I do know a little c# programming.
The first thing I tried was making an animated float that adds the rotation to the Z axis over time, but that went horribly wrong and makes the character jump/skip/glitch all over the place.
The second thing I thought of was to add 2D torque to make him start slipping backwards, but he stays in the same rotation with fixedAngle true.
So then I made it where fixedAngle is false when he is on ice, but he immediately falls forward or backwards as soon as I start running. I made the center of mass right in the middle so he stands fine as long as he is not moving.
Does anybody know a way of achieving the effect I want?
This is my first game and I am a noob, so hopefully there is an easier/correct way of going about this. I could be doing this all wrong, so any guide in the right direction would be greatly appreciated.
It seems like from your verbage, you want to be tracking the amount of time the player has been running on ice.
If you want to tie this to the run key being down, start the timer if the button is down and trigger the "slip-and-fall" event to occur after a certain amount of time.
If you want to tie this to the amount of time the player has been on the ice, start the timer when the player reaches the ice and trigger the "slip-and-fall" event to occur after a certain amount of time.
If you want there to be a visual tilting, tie the time delta to the angle of the object. Set a certain angle to trigger the "slip-and-fall" event.
Update(){
if(this.running && _terrainAtPos == <Ice> && isGrounded){
transform.Rotate(0,0,3*Time.deltaTime);
if(tranform.rotation.z > 180){
//do falling event
}
}
}
EDIT: The above is not a working sample. Just something I whipped up to illustrate.