- Home /
Question by
bart721 · Aug 21, 2017 at 07:39 PM ·
c#collisionplayerplayer movement
When player hit wall continue moving
Hello, I have a problem with moving with the player. When a player moves up or down to turn left or right near by the yellow wall he stops but I want the player to continue moving. Thanks for answers. PS: I'm very beginner with Unity and programming.
Hear PlayerMovement.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player_Movement : MonoBehaviour
{
bool MoveUp;
bool MoveDown;
public float playerSpeed;
Rigidbody2D rb;
void Start ()
{
rb = GetComponent<Rigidbody2D>();
MoveUp = false;
MoveDown = false;
}
public void MoveLeft()
{
rb.velocity = new Vector2 (-playerSpeed, 0);
}
public void MoveRight()
{
rb.velocity = new Vector2 (playerSpeed, 0);
}
public void Moveup (){
MoveUp = true;
MoveDown = false;
}
public void Movedown (){
MoveUp = false;
MoveDown = true;
}
public void StopMove(){
MoveUp = false;
MoveDown = false;
}
void Update () {
if(MoveUp || MoveDown )
{
if(MoveUp )
{
rb.velocity = new Vector2(0, playerSpeed);
}
else if(MoveDown )
{
rb.velocity = new Vector2(0, -playerSpeed);
}
}
}
}
And there is a video: https://youtu.be/-UNj0vEiDU4
Comment
Your answer
Follow this Question
Related Questions
Ammo Pick up C# Not Working? 0 Answers
Multiple Cars not working 1 Answer
Player is moving through walls when force is added from a knockback script? *UNANSWERED* 3 Answers
Moving a box. 1 Answer