Answer the question
In order to leave comments, you need to log in
Character can't push objects?
Hello, on the stage I have a capsule with a Character Controller, a floor and a sphere with a Rigidbody, I also have a script that moves the character to wasd
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine;
public class Player : MonoBehaviour
{
public float speed = 4f;
public float jumpForce = 8f;
public float gravity = 20f;
private Vector3 moveDir = Vector3.zero;
private CharacterController controller;
private void Start()
{
controller = GetComponent<CharacterController>();
}
private void FixedUpdate()
{
if (controller.isGrounded)
{
moveDir = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
moveDir = transform.TransformDirection(moveDir);
if (Input.GetKey(KeyCode.LeftShift) && Input.GetAxis("Vertical") != -1)
{
moveDir *= 2 * speed;
}
else
{
moveDir *= speed;
}
}
if (Input.GetKeyDown(KeyCode.Space) && controller.isGrounded)
{
moveDir.y = jumpForce;
}
moveDir.y -= gravity * Time.deltaTime;
controller.Move(moveDir * Time.deltaTime);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question