Back again with a quick question! I have a few basic platforming mechanics going on in this scene. I have a prefab platform with an animation that loops back and forth between two different x positions, but does not begin looping until OnCollisionStay2D activates with my player object with the tag “Red cube”.
But once the animation starts the red cube has very little friction with the platform and falls off. I have attempted to fix this AddRelativeForce in this script. Is there any way to increase the friction to where my player cube isn’t slipping off? Or is there anyway to script my platform to add constant force to my player where I will move with platform seamlessly? Thank you so much for your time! You guys are a great help
using UnityEngine;
using System.Collections;
public class PlatformMovement : MonoBehaviour {
public Rigidbody2D rb;
public float speed;
void Start()
{
rb = GameObject.FindGameObjectWithTag ("Red Cube").GetComponent<Rigidbody2D> ();
}
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "Red Cube")
{
Debug.Log ("Something has entered this zone.");
GetComponent<Animation> ().Play ("Side To Side");
}
}
void OnCollisionStay2D(Collision2D coll)
{
if (coll.gameObject.tag == "Red Cube")
{
rb.AddRelativeForce(new Vector2(speed, 0), ForceMode2D.Force);
}
}
}