I'm making a 2D platformer and I've come across a really annoying problem where if I move my player character GameObject to another location on the scene, my player becomes stuck and the game spazzes out, jumping from the players original location and the position I moved it to.
My player character is made up of many parts, each a separate GameObject. I know the problem is definitely in my animation, because if I disable the animator component, the problem goes away, just I don't have my animations anymore. I believe the problem may be in the player character's Idle Animation and it's position property. There is no script attached where his starting location is hard coded.
How can I make the child Gameobjects move relative to the parent Player GameObject? I cannot move the player in the scene from its original location without the game glitching up.
Here are some screenshots
[Player and it's parts in Hierarchy]http://i67.tinypic.com/bdlc1j.png
[Idle Animation]http://i64.tinypic.com/2gtp99x.png
[Player's original Location, he works if starting here] http://i66.tinypic.com/261jb6c.png
[Player is Moved, game bugs out] http://i67.tinypic.com/292a2c3.png
Try to disable "Apply Root Motion" flag in the Animator component.
The problem should be related to the fact that the animation changes the position values
My guess is that you have animated the different parts by moving then around in the editor and recording that. This meas that the animation is keeping track of the original position at which you did the animation. Try deleting those parts from the animation.
I couldn't fix the spazzy-jittering problem that occurs when I move the player character to another position on the scene, but I did find a way around it. The problem definitely lied within the Animator component and the gameObject's Rigidbody2d.
Instead of moving the player to another position, I instead made a 'Spawn Point' which the player starts from when first playing the scene, and that was able to be moved freely around. Pretty much:
void start(){
transform.position = spawnPoint.transform.position;
}
Related
My 2d platformer has a "time travel" mechanic.
You place down a hologram at a location (actor with no collision and some pretty effects).
While you hold down the "Rewind" button, your character's collision and gravity are turned off, and he slowly moves towards the hologram.
When you release the rewind button, it turns his collision back on.
My tilemap is set to "block" the pawn (so he can walk on it, etc).
If you release the button while he's overlapping the terrain, and it turns his collision back on, he gets stuck.
I'm wondering what to do. Unity automatically "ejected" an object that was overlapping something it shouldn't be.
Since the terrain is set up to block the pawn, I can't fire an overlap event. "On Component Hit" will fire just from him standing or rubbing against the terrain, so that won't do either.
How should I detect that the player is popping up inside the terrain? I can decide what to do later (eject them, kill them, prevent them from appearing, etc). But for right now I just need to differentiate from them touching the tilemap and being inside it.
Any ideas?
So what I wound up doing was duplicating the capsule collider on my player. The new capsule (called 'Terrain Overlap') ignores all collisions, except it overlaps the tilemap.
The component has a begin and end overlap method that sets a boolean on the character.
When the player lets go of the Rewind button, if they're inside the ground (boolean check), I can fire the death method.
I'm new to Unreal Engine and I want to make a First-Person game. I want my player to climb on top of a cube.
So I created a Camera animation, in order to see that the player is climbing (the camera goes up, then rotates a little, then goes forward). When the player is climbing the cube, I also want their hands to grasp the edge of the platform and push in the upward direction. I don't have a full skeleton, only hands like in the basic first-player example.
So basically, when the player presses space in front of a cube, I'd like to have my camera animation and my hand animation to play at the same time and to be synchronized.
Is there any animation class to do both in the same class ? Like a montage, or a sequence. When I go to animation montage, I can't find anything to import my camera animation.
When I create a new skeleton animation, there is no camera attached to the skeleton so I cannot move the camera and the hands in the same animation.
Thanks for your help!
Root Motion can do this. With Root Motion, you wouldn't animate the camera directly. Instead, you'd animate the character's root bone to move the character capsule (and thus camera). This would keep the camera and hands in sync and also allow you to implement your climb.
Stack Overflow isn't the best place to ask animation questions. I'd recommend one of the following instead:
Anim State (which also has a discord server)
UE4 Animation Forum
So I did an attack animation in the program Aseprite and everything was fine with the animation, but when I put in inside the animator in unity the character changes position.
Here's the images, first one is a gif with the animation running as I want, and then the before and after of the animation in Unity.
I know it's small but I hope you can see
This is because it's setting the center point at the location, and the gif is wider than the standard player image, you will need to offset to compensate.
So I just sliced the sprites again but with the pivot to the left instead of center, and then adjusted the Collider. It seems to work. Not sure if it's the perfect way though.
So basically I want to make a prefab (a cat) climb a wall, I wanna do it with basic root motion animation. Since I am new with unity and is my first time doing this I decided that I need to do a little bit of testing without any complicated animations, that being said, I made a simple animation, just moving the cat prefab, in the animation clip the cat is moving one meter on the +z axis.
When I play the animation without the "Root Motion" check box checked it works just fine, but when I play it with root motion active (by the way, I checked the root motion check box and I clicked on "Generate Root Motion Curves") it plays in a different way. Instead of moving on the +z axis is moving on the -Z with a shorter distance and a shorter time as well and on the +y axis it moves a much shorter distance (I forgot to mention that I moved the prefab on the y axis as well, to simulate a very basic "jump" so to speak). I am using an animator to trigger the animation right when the game starts and the animation is set to loop.
Why does it do that and how can I fix it so the animation is played with root motion exactly like it plays without the "Root Motion" check box checked? What am I doing wrong?
The problem isnt with your animation. The issue is that Root Motion uses the animation to calculate the movement.
If your script is telling the cat to move, and root motion is telling the cat to move, there will be a conflict. When using root motion, comment out the portion of your script that is telling the player to move one meter.
This should allow unity to do its calculation and move the prefab accordingly. For an in depth explanation, see https://docs.unity3d.com/Manual/RootMotion.html
I just recently began using Unity3D and this is my first game, so if I'm not doing things like I'm supposed to, please tell me.
There is a 2D character that I want to move one step forward using the Animation mechanism. This movement can be splitted in two parts :
Move forward the back leg, don't move the upper body ;
Use this leg to push and make the step, moving the upper body.
My problème is that I can't find a way to make this step permanent. As soon as it start looping on the "Idle" animation, then, it come back to the original position (before the step).
I don't know how to let my character stay in the position it was just between the "Step Forward" animation and the "Idle" animation.
I tried to add "Rigidbody 2D", "Box Collider 2D" and "Physics2D Material" on both feet and on the floor, but it somewhat breaks the IK script ("Simple CCD", from the youtube video "Unite 2014 - 2D Best Practices In Unity"). And I'm sure there is a much simpler way.
EDIT: My question was not clear enough. The idle animation is the default animation, where the character is doing nothing in particular. It's just moving a little while it's staying in position. When it runs "Step Forward", all the sprites are moved (only when the back leg is pushing). If all animations are stopped right now, then the character is indeed in a new position, closer to it's opponent. I can check that by removing the transition from "Step Forward" to "Idle". But from here, I want it to loop on the Idle animation. When the transition from "Step forward" to "Idle" is done, the character is NOT running Idle from it's new position, but from it's old position, before the step, as if it was pulled from backward. I want to run Idle from the new position.
Here is a longer gif when we can see more of the Idle animation :
And my Hierarchy panel looks like :
Main Camera
Karateka (the top GameObject container, with the Animator component)
Torso (the sprites)
Head
Right arm
Right leg
Right lower leg
Right foot
...
IK (the Inverse Kinematics targets)
Left fist target
Left foot target
...
Any suggestion is welcome.
If I get it right, you have the StepForward animation running and it gets cut in the middle back to idle. There, the StepForward animation triggers again but from the start and you wish to restart from where you left off:
You can record the normalized value of your StepForward animation and use it next time:
float normValue = this.animator.GetCurrentAnimatorStateInfo(0).normalizedTime;
then you can use that value:
this.animator.Play("StepForward", 0, normValue);
Other possibility, you are not after that but simply you want to pause the animation without getting to Idle.
Use a parameter. You can add a float parameter (call it direction) in the Animator window (top left). Then select a state in the animator, it will open the animation setting in the inspector. Under speed, open the drop down where your new parameter should show up. And tick it.
Now, your direction float will affect the speed of your animation as such:
this.animator.SetFloat("direction", value);
if you give 0, you pause. Give back 1 to move forward. You can also lerp the value so it is not abrupt. Your way.