ara
New vMember
Posts: 22
|
Post by ara on Feb 14, 2020 3:23:14 GMT
Using the VPlatform for a vertical movement and it needs to cover a long distance so I set at a pretty fast speed (10). The issue is that the player doesn't move with the platform, so as the platform is falling the player falls and then lands multiple times.
I solved this by adding a trigger collider around the platform and then adding this script so that player moves relative to the platfrom.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ParentOnTrigger : MonoBehaviour
{
[SerializeField] string parentThisTag = "Player";
public void OnTriggerEnter(Collider other)
{
if (other.tag == parentThisTag)
{
other.transform.SetParent(this.transform);
}
}
public void OnTriggerExit(Collider other)
{
if (other.tag == parentThisTag)
{
other.transform.parent = null;
}
}
}
|
|