Answer the question
In order to leave comments, you need to log in
Charter Controller conflicts with child object, how to fix?
There is a script for turning the camera:
public Transform target;
void Update()
{
float rot_speed = 3f; //коэфицент скорости вращения, чувствительность мыши
Vector3 delta = new Vector3(-Input.GetAxis("Mouse Y") * rot_speed, Input.GetAxis("Mouse X") * rot_speed, 0f);
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + delta);
transform.position = target.position - (transform.forward) + (transform.up);
}
private float speed;
public float graviti;
public float jumpPower;
public float normalSpeed;
public float rotateSpeed;
public Transform head;
private CharacterController ch_controller;
private Vector2 input_normalized;
private Vector3 velocity;
private float force_down;
void Start()
{
ch_controller = GetComponent<CharacterController>();
}
void Update()
{
Move();
}
private void Move()
{
input_normalized.y = Input.GetAxis("Vertical");
input_normalized.x = Input.GetAxis("Vertical");
if (!Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S))
{
input_normalized.y = 0;
}
if (!Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.A))
{
input_normalized.x = 0;
}
if (Input.GetKeyDown(KeyCode.Space) && ch_controller.isGrounded)
{
force_down = jumpPower;
}
if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
{
speed = normalSpeed * 2f;
}
else
{
speed = normalSpeed;
}
if (ch_controller.isGrounded && force_down > 0)
{
force_down = jumpPower;
}
else
{
force_down -= graviti * Time.deltaTime;
}
velocity = ((transform.forward * input_normalized.y + transform.right * input_normalized.x + head.transform.up * force_down) * speed + Vector3.down * force_down) * Time.deltaTime;
ch_controller.Move(velocity);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question