- Home /
Question by
spirachi77 · Apr 04, 2018 at 06:24 AM ·
charactercontrollercharacter controllerpushing
how to make character controllers push eachother?
I am making a game that will have 2 player characters, and I wan them to push each other but solutions I find don't work. Please help
code:
public class PlayerController : MonoBehaviour {
public float moveSpeed;
public float gravScale;
public float jumpForce;
public float vertVel;
public CharacterController controller;
public Vector3 moveVector;
public GameObject opponent;
// Use this for initialization
void Start()
{
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
if (controller.isGrounded)
{
if (Input.GetAxis("Vertical") > 0)
{
vertVel = jumpForce;
}
}
else
{
vertVel -= gravScale * Time.deltaTime;
}
moveVector = Vector3.zero;
moveVector.z = Input.GetAxis("Horizontal") * moveSpeed;
moveVector.y = vertVel;
controller.Move(moveVector * Time.deltaTime);
}
}
Comment
it would help if we could see what controller.$$anonymous$$ove() is
Answer by tormentoarmagedoom · Apr 04, 2018 at 08:57 AM
You need to add a RigidBody component to each player