- Home /
This question was
closed Nov 27, 2018 at 02:39 PM by
$$anonymous$$ for the following reason:
Other
Question by
$$anonymous$$ · Feb 26, 2015 at 03:20 PM ·
c#collisionphysicsrigidbodycharactercontroller
How to change CC script to Rigidbody script
I want to change this script that I wrote that allow's my player to jump so I can use a Rigidbody on my player. The reason why I am change it is because when the player collides with a Rigidbody he get's push I want the player to get push not the enemy (Rigidbody) I don't know if a CC can get push.
public float jumpSpeed = 0.7f;
public float gravity = 2;
CharacterController controller;
Vector3 currentMovement;
// Use this for initialization
void Start ()
{
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update ()
{
if (!controller.isGrounded)
currentMovement -= new Vector3 (0, gravity * Time.deltaTime, 0);
else
currentMovement.y = -9.81f;
if (controller.isGrounded && Input.GetButtonDown("Jump"))
currentMovement.y = jumpSpeed;
controller.Move (currentMovement);
}
}
Comment
Answer by SirMalarkey · Feb 26, 2015 at 03:26 PM
Using a rigidbody instead of a character controller, is very difficult and can lead to issues down the line. If you want your player to be pushed, every time there is a collision you could check the speed and direction of the object that collided with you character controller, then use that to move your character that direction.