Change Gravity Scale When hitting collider

Hi

I want to change the gravity scale of the player, when the player hits a collider. I’ve made a collider, were there player should run slower and jump less high. I’ve tried Point Effector, Area Effector, but it’s not working how I want it to. The point and area effector, pulls him back, but keeps pushim him off my collider.

I just want him to run slower and jump less high, when he hits that collider.

Hope somebody can help me :slight_smile: thanks

Not sure that you can edit the gravity for a SPECIFIC object, however you could turn off the objects gravity, then add a constant downward force lower than the gravity normally is.

This code turns your player’s gravity off when he’s in the collider, and adds a constant downward force that you can modify in the inspector. I didn’t compile this or anything but I hope its a useful reference.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    Rigidbody rb;
    bool useCustomGravity;
    public int customGravity;

    void Start()
    {
        useCustomGravity = false;
        rb = gameObject.GetComponent<Rigidbody>();
    }

    void Update(){
        if (useCustomGravity) {
            rb.AddForce(-Vector3.up * customGravity, ForceMode.Impulse);
        }
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "OtherObject") //collider that slows player
            rb.useGravity = false;
            useCustomGravity = true;
    }

    void OnTriggerExit(Collider other) 
    {
        if (other.gameObject.tag == "OtherObject") 
            rb.useGravity = true;
            useCustomGravity = false;
    }
}

These are some documentations on using gravity for objects. Hope this helps, and good luck!