I have a gun and i am making a gun script but the problem i am having is that the children are moving seperatly. For example the clip and the inside are moving differently. The gun isnt staying together. This is my SetUp:
-Player
-mainCamera
-Glock
-glock 19
-glock_19
-glock_19_sl
-glock_19_mg
my playermovement scirpt is:
public float walkSpeed = 5;
public float runSpeed = 10;
private float movementSpeed = 5;
public float mouseSensitivity = 2;
private float verticalRotation = 0;
public float upDownRange = 60;
private float verticalVelocity = 0;
private CharacterController controller;
public float jumpSpeed = 20;
void Start ()
{
movementSpeed = walkSpeed;
controller = GetComponent<CharacterController>();
}
void Update ()
{
// Rotation
float rotLeftRight = Input.GetAxis("Mouse X") * mouseSensitivity;
transform.Rotate(0, rotLeftRight, 0);
verticalRotation -= Input.GetAxis("Mouse Y") * mouseSensitivity;
verticalRotation = Mathf.Clamp(verticalRotation, -upDownRange, upDownRange);
Camera.main.transform.localRotation = Quaternion.Euler(verticalRotation, 0, 0);
if (Input.GetKey(KeyCode.LeftShift))
{
movementSpeed = runSpeed;
}else{
movementSpeed = walkSpeed;
}
// Movement
float forwardSpeed = Input.GetAxis("Vertical") * movementSpeed;
float sideSpeed = Input.GetAxis("Horizontal") * movementSpeed;
if (controller.isGrounded)
{
if (Input.GetButtonDown("Jump"))
{
verticalVelocity = jumpSpeed;
}
}else{
verticalVelocity += Physics.gravity.y * Time.deltaTime;
}
Vector3 speed = new Vector3(sideSpeed, verticalVelocity, forwardSpeed);
speed = transform.rotation * speed;
controller.Move(speed * Time.deltaTime);
}
this script is only on the player. This is the only script or component on any of the objects.
why are the glock_19, the glock_19_sl, and the glock_19_mg moving seperatly from the Glock? They are children but are still moving seperatly. Why?