- Home /
Question by
ttroenigk · Aug 02, 2020 at 01:19 AM ·
c#cameracamera rotatecamera-lookinput.getaxis
How to rotate player based off my current code
transform.position = target.position - offset;
transform.LookAt(target);
if (Input.GetMouseButton(1))
{
offset = Quaternion.AngleAxis(Input.GetAxis("Mouse X") * turnSpeed, Vector3.up) * offset;
offset = Quaternion.AngleAxis(Input.GetAxis("Mouse Y") * turnSpeed, Vector3.left) * offset;
//target.Rotate(0, horizontal, 0);
//pivot.Rotate(-vertical, 0, 0);
if (transform.position.y < target.position.y)
{
transform.position = new Vector3(transform.position.x, target.position.y, transform.position.z);
}
}
I have this in update. How can I change my 2 offsets in right click to be different variables then - them from target position to rotate player as well as camera?
void Update()
{
//rb.velocity = new Vector3(Input.GetAxis("Horizontal") * moveSpeed, rb.velocity.y, Input.GetAxis("Vertical") * moveSpeed);
//float yStore = moveDirection.y;
moveDirection = (transform.forward * Input.GetAxis("Vertical"))+(transform.right*Input.GetAxis("Horizontal"));
moveDirection = moveDirection.normalized*moveSpeed;
//moveDirection.y=yStore;
isGrounded = Physics.Raycast(transform.position, Vector3.down, distanceToGround);
if (rb.velocity.y <= 0 && isGrounded)
{
currentJumpNumber = 0;
}
if (Input.GetButtonDown("Jump")&¤tJumpNumber<jumpNumber)
{
rb.velocity = new Vector3(rb.velocity.x, jumpForce, rb.velocity.z);
currentJumpNumber++;
}
rb.MovePosition(rb.position + moveDirection*Time.deltaTime);
}
I have this for mvoement.
if someone can help me get my camera rotating correctly and player id appreciate it.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613004652im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Free camera look question 2 Answers
How to make the player direction change with the camera rotation? 1 Answer
How to make my Camera Controller look at target 0 Answers
make a target camera? 1 Answer