In Unity3d using the FPS Controller, how can I keep a constant player speed when auto-walk forward using transform.forward? -
using unity3d first person controller, want player move forward automatically in direction camera looking at. should behave same using arrow keys, except keep arrow key "pressed". have working in script below, player slows down rotates first-person camera away 0 degrees on y-axis. when looking towards 0 degrees on y-axis, player speed normal again.
how can modify script below player moves @ constant speed, no matter camera rotation?
i set script on first person controller parent node:
public var head : gameobject; private var motor : charactermotor; // use initialization function awake () { motor = getcomponent(charactermotor); } // update called once per frame function update () { // retrieve forward direction based on camera rotation var directionvector = transform.forward; directionvector.y = 0; directionvector.normalize(); // apply direction charactermotor motor.inputmovedirection = transform.rotation * directionvector; motor.inputjump = input.getbutton("jump"); } // require character controller attached same game object @script requirecomponent (charactermotor) @script addcomponentmenu ("character/fps input controller")
multiply movement time.deltatime time time between frames.
example copy http://docs.unity3d.com/scriptreference/time-deltatime.html
function update () { // move object 10 meters per second! var translation : float = time.deltatime * 10; transform.translate (0, 0, translation); }
Comments
Post a Comment