I try to make a game with a ball that is moving, rotating and can jump to the sides.
My question is how can I make two animations? I know about layers and AddMixingTransform but I never used them. I dont have a human body where i would need different parts to move. I just have a ball.
Atm the ball moves forward with the help of an parent object. And the ball itself has the rotation and the jumping animations but just one of them works at a time. I need the ball to rotate and then to jump when I press a button.
Don’t use animations for this. Add a Rigidbody component to your sphere and then use the AddForce und AddTorque script functions to make your sphere move and spin on key presses. This looks more realistic and can be combined to create complex movements.
The ball moves like i want it to and it also have a rotation (because its moving on the ground). But now I also want the Ball to jump to right/left. When I do the jumping with an animation it always resets the position of the ball.
Can I avoid the reset or do the jumping with another way?
Actually I never thought about it, but it wouldn’t work. The ball jumps between three different plattforms and if the jump isn’t as pefect as the animation-jump the ball would fall off the plattform (due to physics)
Sorry, but I have trouble understanding, what you’re trying to achieve. Could you do some kind of illustration or animation? Other platformers do use physics exclusively for their character.
In my game are three plattforms, between the plattforms is nothing. The ball starts on the middle plattform and moves forward. By pressing a key the ball can jump up, left or right. When the ball jumps left or right it lands on the left/right plattform. It works so far, the only thing that is missing is the rotation of the ball.
I still think you can do this with physics alone. You need a script that adds forces in different directions (up, left, right) depending on the key pressed. And then you can add the torque on top of that for the rotation. If you want a constant forward motion you can add a constant force.
You don’t need to use gravity (at least I think that’s what you mean). If you want the ball to stop cold on hitting a platform, you can do this with a script on a collision event, that sets the velocity and angularVelocity to zero.
Really it would be easier to understand what you want with a drawing.
Create a script for the ball that reacts to three keys. Let’s call them Left, Right and Forward.
When Forward is pressed, add a force in the forward direction (z-axis in your image).
When Left is pressed, add a force to the left (-x-axis)
When Right is pressed, add a force to the right (+x-axis)
In the update function, continuously test the x value of the ball’s transform.position. When the ball collides with a platform, assign a new vector to Rigidbody.velocity with the z value set to the old forward velocity and the x and y values set to zero. This stops the ball’s sideways movement. Now use transform.position and Vector3.Lerp to move the ball to the center of the platform.
One final thing: Disable the collider of the platform, the ball is currently moving on, or it won’t be able to leave.