- Home /
Make Character Controler can run with diffrent float
private void characterControler(){
GroundedPlayer = p_Character.isGrounded;
if(GroundedPlayer && p_Velocity.y < 0){
p_Velocity.y = 0f;
}
Vector2 movement = MovementControl.action.ReadValue<Vector2>();
Vector3 move = new Vector3(movement.x, 0f, movement.y);
move = cameraMain.forward * move.z + cameraMain.transform.right * move.x;
move.y = 0f;
p_Character.Move(move * Time.deltaTime * walkSpeed);
if (JumpControl.action.triggered && GroundedPlayer){
p_Velocity.y += Mathf.Sqrt(jumpHeight * -3f * gravityValue);
}
p_Velocity.y += gravityValue * Time.deltaTime;
p_Character.Move(p_Velocity * Time.deltaTime);
if (movement != Vector2.zero){
float targetAngle = Mathf.Atan2(movement.x, movement.y) * Mathf.Rad2Deg + cameraMain.transform.eulerAngles.y;
Quaternion rotation = Quaternion.Euler(0f, targetAngle, 0f);
transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime * RotationSpeed);
}
RunControl.action.started += press_Run;
RunControl.action.canceled += relese_Run;
void press_Run(InputAction.CallbackContext ctx){
RunControl.action.performed -= press_Run;
anim.SetBool("isRun", true);
}
void relese_Run(InputAction.CallbackContext ctx){
RunControl.action.performed -= press_Run;
RunControl.action.started -= press_Run;
anim.SetBool("isRun", false);
}
}
Answer by VerZnox · May 03 at 10:43 AM
took a while... but I resolve it by my self as I can see the walkSpeed
is the main of the character control to move to 3D world Vector3
and i just add some new float variable and change walkSpeed
to a playerSpeed
add new variable of float to walkSpeed
and now. it work as I wanted
private void characterControler(){
GroundedPlayer = p_Character.isGrounded;
if(GroundedPlayer && p_Velocity.y < 0){
p_Velocity.y = 0f;
}
Vector2 movement = MovementControl.action.ReadValue<Vector2>();
Vector3 move = new Vector3(movement.x, 0f, movement.y);
move = cameraMain.forward * move.z + cameraMain.transform.right * move.x;
move.y = 0f;
p_Character.Move(move * Time.deltaTime * playerSpeed);
if (JumpControl.action.triggered && GroundedPlayer){
p_Velocity.y += Mathf.Sqrt(jumpHeight * -3f * gravityValue);
}
p_Velocity.y += gravityValue * Time.deltaTime;
p_Character.Move(p_Velocity * Time.deltaTime);
if (movement != Vector2.zero){
float targetAngle = Mathf.Atan2(movement.x, movement.y) * Mathf.Rad2Deg + cameraMain.transform.eulerAngles.y;
Quaternion rotation = Quaternion.Euler(0f, targetAngle, 0f);
transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime * RotationSpeed);
}
RunControl.action.started += press_Run;
RunControl.action.canceled += relese_Run;
void press_Run(InputAction.CallbackContext ctx){
RunControl.action.performed -= press_Run;
anim.SetBool("isRun", true);
move *= playerSpeed = runSpeed;
}
void relese_Run(InputAction.CallbackContext ctx){
RunControl.action.performed -= press_Run;
RunControl.action.started -= press_Run;
anim.SetBool("isRun", false);
move *= playerSpeed = walkSpeed;
}
}
Answer by CodeMonkeyYT · May 02 at 05:17 PM
What does "different float" mean? Different speed? Change the value you have in walkSpeed
I want to make the "different float", from the walkSpeed to overwrite to the runSpeed float that i have
Your answer
Follow this Question
Related Questions
Boosting Character Controller Problem 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
player isn't rotating along y-axis 1 Answer
OnCollisionEnter Sine Wave to Character 0 Answers