1
\$\begingroup\$

I'm trying to change the velocity of a character controller component on a Third Person Controller, but when I try to change it, the console says the velocity is read only. This is my code.

P.GetComponent(CharacterController).velocity = 0;

(P is my player GameObject variable)

So, any ideas on how to change this?

Thanks, Chris.

\$\endgroup\$
2
  • \$\begingroup\$ After reading more about the CharacterController component, if you want to do custom things with it, you'll likely have an easier time creating your own controller. \$\endgroup\$
    – House
    Jul 11, 2014 at 2:34
  • \$\begingroup\$ If you try using new Vector3() instead of 0.0f what happens? \$\endgroup\$
    – firebellys
    Jul 12, 2014 at 20:01

1 Answer 1

1
\$\begingroup\$

As that error clearly states, that value is read-only; you cannot set it directly. The 'velocity' property of a CharacterController is a side-effect of movement commands to the object. So you attempt to move the object, then collision detection is applied, then the 'velocity' property is set to tell you how much the object actually moved. The relevant documentation:

Note: The velocity returned is simply the difference in distance for the current timestep before and after a call to CharacterController.Move

The way to move a CharacterController is using the Move() function.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .