Sprite starts moving when on collision is detected

Updated on January 31, 2016 in  [R] 2D Graphics
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
3 on January 31, 2016

Hey!

Like the title says, I have a problem when my Sprite gets in contact with wall, the Sprite starts moving in right direction. I have disabled gravity and I really don’t have any clue what could it be. Thanks for all the answers. Umm, and yea, I’m a beginner in Unity.

GIF of the problem

EDIT: 
The script that is attached to Sprite soldier.

using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
 private Vector3 input;
 public float maxSpeed = 10f;
 // Use this for initialization
 void Start () {
 }
 // Update is called once per frame
 void Update () {
 float inputVertical = Input.GetAxis ("Vertical");
 float inputHorizontal = Input.GetAxis ("Horizontal");
 GetComponent().velocity=new Vector2 (inputHorizontal*maxSpeed,inputVertical*maxSpeed);
 }
 void OnCollisionEnter(){
 GetComponent().velocity = Vector3.zero;
 }
}

  • Liked by
Reply
0 on January 31, 2016

Provide script maybe?

  • Liked by
Reply
Cancel
0 on January 31, 2016

From the GIF, i’d say you are acumulating force from hitting the wall

  • Liked by
Reply
Cancel
0 on January 31, 2016

I edited and added basic script i have attached to object

  • Liked by
Reply
Cancel