I have this:
void Update() {
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
However, I want it to be more game-style ish.
Like when I press W, I want it to move forward at “Speed” fast.
And I want to be able to press A (left) while in-air and actually move left.
Anyway I can do this? Anyone have the code for this? Anything?
there should be a standart Script integrated …
older Post
If you have ever used the built-in FPS character, you would know it stinks lmfao.
I need something more cartoon-ish game style like I said above.
Prella
April 5, 2020, 9:10pm
4
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController controller;
public float speed = 12f;
// Update is called once per frame
void Update()
{
float x = Input.GetAxis(“Horizontal”);
float z = Input.GetAxis(“Vertical”);
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.deltaTime);
}
Rigidbody has the parameter on the AddForce method() which you can set to ForceMode.Impulse I believe. this simulates a sharp and sudden force along a given axis. I.e. jumping! and you can apply a sideways force to still get that motion mid-air.
Putcho
March 26, 2021, 5:44pm
6
Anyway I can do this?
yes you can
move this code out side the if(controller.isGrounded) and put it above if(controller.isGrounded)
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
do that you should be able to move mid air
iSleepzZz:
void Update() {
CharacterController controller = GetComponent();
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis(“Horizontal”), 0, Input.GetAxis(“Vertical”));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton(“Jump”))
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
so where do we have to put it in?? in the start function or the update function??