Question by
OmerPasa3328 · Aug 06, 2021 at 10:55 PM ·
animationmovementparent-child
When animator activated child object flies or stops?
I animated child of the parent but it works in test project perfectly. Though in main project ,it just flies or stops even though it doesn't have any animations activated.
NOTE:I don't need idle animation so I emptied a animation and put it , otherwise it will play unnecessary animations.
though when it flies it shouldn't ? I restricted movement in rigidbody so it shouldn't fly but it is. :(
MY MOVEMENT CODE:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class crowbarmove : MonoBehaviour
{
void Start()
{
transform.position = new Vector3(0.5f,4.186f,3.114f); // Ä°nitializing place of the player
GetComponent<Rigidbody>().velocity = new Vector3(-5,0,0); //starting movement
// parent and child had to have rigidbody to work!!
}
void Update()
{
//this if makes sure , crowbar in certain positions
if (transform.position.z <= 0.08 || transform.position.z >=4.66)
{
// Create values between this range (minY to maxY) and store in yPos
float zPos = Mathf.Clamp(transform.position.z, 0.113f,3.161f);
// Assigns these values to the Transform.position component of the Player
transform.position = new Vector3(transform.position.x, transform.position.y, zPos);
}
transform.position = new Vector3(Mathf.Clamp(transform.position.x, 0.5f, 0.5f), transform.position.y, transform.position.z);
// this is an infinite runner so it gotta move right and left 2 if codes does these jobs.
if (Input.GetKeyDown(KeyCode.A))
{
Vector3 position = transform.position;
position.z += 1.5f;
transform.position = position;
}
if (Input.GetKeyDown(KeyCode.D))
{
Vector3 position = transform.position;
position.z -= 1.5f;
transform.position = position;
}
}
}
Comment