- Home /
Switching from SimpleMove to Move
Hi there!
I have an AI driven character that has been using CharacterController.SimpleMove so far, and all good. But now I need this character to jump. When trying to switch over CharacterController.Move, my character suddenly starts moving in a different manner, even if I use the same direction vector.
I used to move my character this way:
Vector3 dir = (targetPosition - transform.position).normalized;
dir *= speed * Time.fixedDeltaTime;
controller.SimpleMove (dir);
If I just change ".SimpleMove" in this code to ".Move" , the character will run move much faster. Why is that? What can I do to behave same way as with SimpleMove?? Is it because of the gravity? What is the gravity SimpleMove applies?
Thanks!
Did you check if the character is grounded ?
look this sample code below
public float jumpSpeed_ = 8.0F;
public float gravity_ = 20.0F;
public float acceleration_ = 10.0F;
public float maxSpeed_ = 100.0F;
public float curSpeed_ = 10.0F;
private Vector3 moveDirection = Vector3.zero;
public CharacterController controller_;
// Update is called once per frame
void Update () {
if(controller_.isGrounded)
{
// We are grounded, so recalculate
// move direction directly from axes
curSpeed_ += acceleration_;
if(curSpeed_ > maxSpeed_)
curSpeed_ = maxSpeed_;
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= curSpeed_;
if(Input.GetButton ("Jump"))
{
moveDirection.y = jumpSpeed_;
}
}
// Apply gravity_
moveDirection.y -= gravity_ * Time.deltaTime;
// $$anonymous$$ove the controller_
controller_.$$anonymous$$ove(moveDirection * Time.deltaTime);
}
Answer by Zinger · Dec 19, 2012 at 12:12 AM
SimpleMove is frame rate independent under the hood, meaning that it takes the input and multiplies it by Time.deltaTime (or at least that's what I assume).
Move on the other hand does not do that. So to convert from SimpleMove to Move, take your input to SimpleMove and multiply it by Time.deltaTime.
Oh and also, SimpleMove applies gravity. So there's that too.
Your answer
Follow this Question
Related Questions
CharacterController Move vs. SimpleMove 1 Answer
Character Controller Won't SimpleMove() 0 Answers
NPC CharacterController doesn't move or stops randomly 0 Answers
SimpleMove not working on iOS? 0 Answers