Search Unity

Detect Collision Without Physically Effecting the Player

Discussion in 'Editor & General Support' started by downhilldan, Feb 20, 2017.

  1. downhilldan

    downhilldan

    Joined:
    Nov 16, 2016
    Posts:
    90
    Hi All,

    So what I need to be happening in my game is when the player flies through a cloud, their fuel is decreased at an increased rate throughout the time that they are touching/inside of the cloud.

    I have it detecting the collision between the player and the cloud, but it physically effects the player by throwing them off course (basically turns the clouds into rocks and the player glitches through them and is thrown out in a random direction... :confused:). Ive attached the screenshots on how I have the colliders set up below.

    Is there a way to constantly detect a collision but not physically effect the player?

    Script:
    Code (CSharp):
    1. void OnCollisionStay (Collision test)
    2.     {
    3.         if (test.gameObject.tag == "Cloud")
    4.         {
    5.             PlayerControls.fuel = Mathf.MoveTowards (PlayerControls.fuel, 0, Time.fixedDeltaTime * 2);
    6.             Debug.Log ("Cloud Contact");
    7.         }
    8.     }
    Thanks! :)
     

    Attached Files:

  2. greg-harding

    greg-harding

    Joined:
    Apr 11, 2013
    Posts:
    524
  3. downhilldan

    downhilldan

    Joined:
    Nov 16, 2016
    Posts:
    90