- Home /
How to make character move up walls and along the ceiling?
I am making a 2d metroidvania style game where you can morph into a ball. Progress has been great, but I am trying to add a way to climb up certain walls and ceilings when in morph ball mode. If you have played the metroid prime games it is supposed to be similar to the spiderball. Here is the code I have at the moment.
void OnTriggerStay2D(Collider2D other){
//Magnetic Sphere Controller
if(other.name == "Rail"){
if(isMorphed == true){
if(Input.GetKey (KeyCode.B)){
transform.position = new Vector2( transform.position.x, GameObject.Find("Rail").transform.position.y );
onRail = true;
if( Input.GetKey( KeyCode.RightArrow ) ){
_animator.Play( Animator.StringToHash( "morphRoll" ) );
normalizedHorizontalSpeed = 1;
}
else if( Input.GetKey( KeyCode.LeftArrow ) ){
_animator.Play( Animator.StringToHash( "morphRoll" ) );
normalizedHorizontalSpeed = -1;
} else { _animator.Play( Animator.StringToHash( "morphIdle" ) );}
btw I know those if statements could be combined into one. I copied segments of code from my update function and didnt combine them after. Every part of this code works except for the movement. The characters position works when holding down B, but I cannot move left or right while I am attached to the rail. Is there a better way to do this? I have most of the update function that controlls the character disabled with the onRail variabled, so I want the movement on rail to be controlled in this function alone.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Enemy's health wont get set from different script. 1 Answer
Player Tips - Have triggers act independently 1 Answer