So, right now when my character hits an enemy they kind of fly back, but it seems they stop half way through and fall straight down. This causes it where the duck catches up and you end up falling on the enemy again. Mind you, if you press to move then its not an issue, but just looking for a better way to have this work.
Jump function called when hit. I think this is where I need to work on it, but could be wrong.
void jumpBack()
{
if(testCollide)
{
MoveSpeed = 100f;
jump();
for(int i=0;i<8000;i++)
{
MoveVector -= new Vector3(10f * Time.deltaTime,0,0);
}
MoveSpeed = 20f;
}
}
Jump code I found and used:
public void jump(){
if(CharacterController.isGrounded){
VerticalVelocity = JumpSpeed;
}
}
Movement code I found and am using:
void processMovement(){
//transform moveVector into world-space relative to character rotation
MoveVector = transform.TransformDirection(MoveVector);
//normalize moveVector if magnitude > 1
if(MoveVector.magnitude > 1){
MoveVector = Vector3.Normalize(MoveVector);
}
//multiply moveVector by moveSpeed
MoveVector *= MoveSpeed;
//reapply vertical velocity to moveVector.y
MoveVector = new Vector3(MoveVector.x, VerticalVelocity, MoveVector.z);
//apply gravity
applyGravity();
//move character in world-space
CharacterController.Move(MoveVector * Time.deltaTime);
}
void applyGravity(){
if(MoveVector.y > -TerminalVelocity){
MoveVector = new Vector3(MoveVector.x, (MoveVector.y-Gravity*Time.deltaTime), MoveVector.z);
}
if(CharacterController.isGrounded MoveVector.y < -1){
MoveVector = new Vector3(MoveVector.x, (-1), MoveVector.z);
}
}
Any advice on what to do to make this work better?