# Player Rotation with Forward Motion and Jump

OK I am going to re-post this because I don’t think the last one was clear enough.

I want to be able to Rotate the Player when standing in place or using the forward/backward so that the rotation alone is what makes it turn and when i let go of the right or left turn the direction the character is facing is the direction it will move.

I want the player to also be able to Jump and that when I hit the Jump key, in this case I would rather it be “Shift Key,” actually Makes it Jump and not stop all the other motions. So if I am moving forward, I Jump and move forward.

If I stand still I jump up and down standing in the same position, If I turn to rotate and hit jump without moving forward or backward, I want to be able to jump and turn at the same time.

1. I AM NOT CALLING FOR ANIMATIONS IN THIS SCRIPT YET.
2. I NEED THE SCRIPT TO WORK WITH WORLD PHYSICS.

OK< so I think i made myself clear.

Now for the Problem.

I Can only jump up and down and it stops all other movement. I can move again when it lands

Here is the Script that I added the Rotation ability to.

`````` void Update()
{
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded)
{
///This is the PROBLEM area, no where else.

Vector3 forward = transform.TransformDirection(Vector3.forward);
float curSpeed = speed * Input.GetAxis("Vertical");
transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);
controller.SimpleMove(forward * curSpeed);
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
``````

. The whole code setup is

``````using UnityEngine;
using System.Collections;

public class PlayerControl : MonoBehaviour
{

public float speed = 3.0F;
public float rotateSpeed = 3.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;

void Update()
{
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded)
{

Vector3 forward = transform.TransformDirection(Vector3.forward);

float curSpeed = speed * Input.GetAxis("Vertical");

transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);

controller.SimpleMove(forward * curSpeed);

if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;

}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}
``````

Now then, I have used other types of Movement options but the jump function does not work or it works and the rotation does not, or the rotation and jump works, but the forward and backward does not.

The problem is Specific to the MOVE F/B and the ROTATION L/R. These work together fine in the form I have shown.

This does not work for me because there is NO ROTATION and regsardfless of the colliders or rigidbody it makes character pass through other objects that have mesh colliders or any other collider for that matter.

``````transform.Translate(moveSpeed * Input.GetAxis("Horizontal") * Time.deltaTime, 0f, moveSpeed * Input.GetAxis("Vertical") * Time.deltaTime);
``````

Yes i can add the jump to it and it Jumps fine. Fine, and dany, that does not resolve the fact I need the movement and rotation to detect and use the physics detection which is what the code I am using does properly,

If you don’t understand exactly what I am saying, than take this code form;

`````` public float speed = 3.0F;
public float rotateSpeed = 3.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;

void Update()
{
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded)
{

Vector3 forward = transform.TransformDirection(Vector3.forward);

float curSpeed = speed * Input.GetAxis("Vertical");

transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);

controller.SimpleMove(forward * curSpeed);

if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;

}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}
``````

Out it on a capsule and add the rigid body with the Character Controller with Step offset at 1, so it actually can use steps and curbs, blah blah blah, and lock the rigid body constraints like they should be to Position Y and check Rotation X,Y, Z so the character wont go flying off if it bumps something, which is how its suppose to work anyways

Now move it around and try and jump while moving.

So, I have in fact gone over the scripting area in the tutorials, I have watched the Often vague and many times misleading demo videos, and cross compared to even get this far.

So I will ask One more time in this Question;

HOW do I modify the rotation and movement code to work as it currently does and get the jump function working properly without it making some weird Wide Sweeping effect and move and turn and jump individually and simultaneously pending the keys i press as anyone playing a game would expect from NORMAL player movement and Jumping?

I DON’T CARE ABOUT, nor WANT this movement dependent on MouseLook

And No I am not and do not want to wast my time with a MouseLook Script used for this type of body motion because that will just cause a flying effect and frankly is useless beyond head movement which irritates to no end because its lack of accuracy and pointer slipping off center, but that is a whole other issue.

1. VISUAL EXAMPLES

All I did was clone the Player Dummy to show path. Im not looking for some sort of tracer motion effect.

Hard to tell in this but as i show if i hit right key and up key it moves like it is suppose to. If i let go of the up key then it turns in place like it is suppose to. Jump is not working with this code like it is suppose to.

This video explain and answer to all of your questions: https:// youtu.be /Sqb-Ue7wpsI
Look at the video description. You need to watch from this timings:
(0:35:35) PlayerMovement and Jumping script
(1:02:07) First Person Mouse Look script
(1:33:14) Sprint and crouch script