adjust the player in the ground And movements

Hi

how to catch the ‘direction’ of the vertex/polygon to apply to the character? the point of it be adjusted to the ground.

Exemple:

alt text

the ground in green is only a picture with component polygon collider.

Question 2:

using a simple script that uses rigidbody2d to move the player,I found some problems:
using rigidbody the player slide When it gets on a mountain.
to climb a mountain is more difficult than to descend.
is there any alternative for this? or the rigidbody2d?
(“put the seriousness of the player in the direction of the object could solve this”)

//C#
void OnCollisionStay (Collision col) {
if (col.collider.gameObject.tag == “Ground”) { //Check the collider is ground
transform.up = col.contacts[0].normal;
}
}

//JS
function OnCollisionStay (col : Collision) {
	if (col.collider.gameObject.tag == "Ground") { //Check the collider is ground
		transform.up = col.contacts[0].normal;
	}
}

Ok. I made a short example of what you are trying to achieve. What you need is a ground with some 2D collider and a Player object with this script only. I still don’t have enough time to polish it, but you will get the picture:

using System;
using System.Collections.Generic;
using System.Collections;
using UnityEngine;

public class Player : MonoBehaviour
{
private void Update()
{
    RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector3.down, Mathf.Infinity);

    // Get the perpendicular normal
    Vector3 direction = new Vector3(hit.normal.y * -1, hit.normal.x);
    // Move right
    if (Input.GetKey(KeyCode.D))
    {
        transform.position += direction * -1 * Time.deltaTime;
        transform.localScale = new Vector3(1, transform.localScale.y, transform.localScale.z);
        transform.rotation = Quaternion.LookRotation(Vector3.forward, hit.normal);
    }
    // Move left
    else if (Input.GetKey(KeyCode.A))
    {
        transform.position += direction * Time.deltaTime;
        transform.localScale = new Vector3(-1, transform.localScale.y, transform.localScale.z);
        transform.rotation = Quaternion.LookRotation(Vector3.forward, hit.normal);
    }
}
}

This example does not rely on physics therefore you need to implement your own rules for gravity and other stuff, but the result can be observed when you hit play. In real good platformer kind of game it’s good to set your own rules even if it’s harder at first.