Last active
January 18, 2019 17:35
-
-
Save TheCuttlefish/cdaf7063601e8514b3f66f21f8807320 to your computer and use it in GitHub Desktop.
Skateboarding Mechanic in 2D (align to ramp normals)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class AllightToNormal : MonoBehaviour | |
{ | |
public float speed; | |
void OnCollisionStay2D(Collision2D col) | |
{ | |
Debug.DrawLine(transform.position, col.contacts[0].point, Color.green); | |
var newNormal = new Vector2(transform.position.x, transform.position.y) - col.contacts[0].point; | |
transform.up = Vector2.Lerp(transform.up, newNormal, 20f * Time.deltaTime); | |
// transform.up = col.transform.up; | |
//regular vector up rotation on collision | |
} | |
private void Update() | |
{ | |
//basic input | |
Rigidbody2D rb = GetComponent<Rigidbody2D>(); | |
rb.velocity = new Vector2 (Input.GetAxis("Horizontal") * speed, rb.velocity.y); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment