- Home /
Need help creating certain character control
Hello, I'm trying to make a game with a style of controls similar I guess to .hack//sign. But I'm finding it to be rather difficult.
What I want: The player moves with w,a,s,d and uses the mouse to orbit the camera around the player. When the player moves it is determined by the rotation of the camera. So if he's/she's holding right while rotating the camera the character will keep running right and adjusting to the camera rotation.
What I have: I have tried several styles of movement including the built in character controller, the below code, and my own code (which couldn't get it to have successful realistic movement/gravity. But so far to no success. What I'm mostly having trouble with is the rotation and angles which greatly effect my movements.
#pragma strict
var speed : float = 6.0;
//var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
function Update() {
if (Input.GetKey ("w")){
this.transform.localRotation = gameObject.Find("CameraHolder").transform.localRotation;
}
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
// if (Input.GetButton ("Jump")) {
// moveDirection.y = jumpSpeed;
}
// }
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}
Anyways, I'm completely lost and would value any help.