- Home /
Question by
cjjacobs97 · Oct 29, 2017 at 10:26 PM ·
rigidbodyunity 2dcharactercontrollervelocityaddforce
2D metroid boost ball
I am recreating the boost ball from metroid prime in 2d and everything is working fine, but only if you are going right. If I try and boost going left it pretty much teleports me in that direction instead of adding force. here is my code
void Update(){
//Velocity Sphere Controller
if(Input.GetKey (KeyCode.G)&& isMorphed == true && onRail == false && onRail2 == false){
boostSpeed = boostSpeed +2;
}else if(Input.GetKey (KeyCode.G)&& isMorphed == true && onRail == true || onRail2 == true){
boostSpeed = boostSpeed +.3f;
}if(Input.GetKeyUp (KeyCode.G) && Input.GetKey (KeyCode.RightArrow) && isMorphed == true){
_velocity.x = Mathf.Sqrt( boostSpeed * normalizedHorizontalSpeed * -gravity );
boostSpeed = 0;
}
if(Input.GetKeyUp (KeyCode.G) && Input.GetKey (KeyCode.LeftArrow) && isMorphed == true){
_velocity.x = Mathf.Sqrt( boostSpeed * normalizedHorizontalSpeed * -gravity );
boostSpeed = 0;
}
}
Comment