I have a system that will aways adjust the movement with a target in this function:
public void HorizontalMovement(Transform target)
{
Rigidbody rigidbody = characterManager.rb;
rigidbody.velocity = Vector3.zero;
Vector3 inputDirection = characterManager.characterEngine.behaviourStack[0].directionStateData.localDirection;
Vector3 up = rigidbody.transform.up.normalized;
Vector3 backward = (rigidbody.position - target.position).normalized;
Vector3 right = Vector3.Cross(backward,up);
backward.y = 0;
right.y = 0;
Vector3 moveVectorHandler = Vector3.zero;
moveVectorHandler = (inputDirection.x * right);
moveVectorHandler += (inputDirection.z * -backward);
rigidbody.velocity = moveVectorHandler * horizontalSpeed;
}
works very well for AI, but im trying to add a player controller above all that.
i want that foward is foward in relation to the camera, not in relation to the target, but i cant remove the target, so i need to adjust the inputs before and my math skills are very limited
this is the player scrip part that will modify the inputs before i send to the script that will move the player:
private void Update() {
inputHandler.UpdateWithPlayerInputs();
UpdateMoveInputsRelativeToCamera();
characterManager.characterEngine.OvewriteBehaviour(behaviourFabric.CreateBehaviour(target.transform,inputHandler.directions,0,0));
}
public void UpdateMoveInputsRelativeToCamera() {
Vector3 direction = Vector3.zero;
Vector3 up = transform.up;
Vector3 foward = -(transform.position - target.transform.position).normalized;
Vector3 right = Vector3.Cross(foward,up);
Vector3 camFoward = camTransform.forward;
Vector3 camRight = camTransform.right;
camFoward.y = 0;
camRight.y = 0;
foward.y = 0;
right.y = 0
//i have no ideia what to do
direction.Normalize();
inputHandler.directions.x = direction.x;
inputHandler.directions.y = direction.z;
}
thanks for everyone, and sorry if something is unclear my english is not very good, and dont know exactly how to explain this problem