- Home /
Move my character quickly like a dodge?
Hello, I want to give the character controller a new ability, a boost It would be like this: when I press E+ a button for a direction, I want my character controller to quickly move to this direction (like if i'm looking in front of me, and I press the left arrow of the keyboard, then my character controller will be pushed at the left) Its like a "dodge" How do i write this? and how can i choose the speed of the boost?
if (Input.GetKey(KeyCode.E))
{
if (Input.GetKey(KeyCode.Z))
{
isUsingBoost = (true);
//moveDirection = Vector3.forward;
//moveDirection = transform.forward*speed*5;
//moveDirection *= speed*5;
//transform.position += new Vector3(speed * Time.deltaTime, 0.0f, 4.0f);
Vector3 speed = new Vector3(0, 0, 10);
cm.SetVelocity(new Vector3(cc.velocity.x,0,cc.velocity.z));
}
This is what i found for now but its not working
Answer by Qasem2014 · Jan 04, 2015 at 10:53 AM
maybe Transform.Translate solve your problem ! it have a speed and direction . you should get a reference to component and the speed variable to make it faster or slower like this :
GetComponent().speed+=5 OR GetComponent().speed-=5
also ConstantForce component is very handy :) this component add force to 3d word space OR game object direction ;)
Answer by Qasem2014 · Jan 04, 2015 at 10:55 AM
GetComponent(yourcomponentname).speed+=5; //when a key pushed
GetComponent(yourcomponentname).speed-=5; //when a key released