Question by
skippynose2 · Jul 19, 2017 at 12:00 AM ·
c#triggerplayertransform.positionplatform
Player Can Not get off platform
Okay so far I have been able to get my player to move with the platform. But there seems to be a problem to when the player is a child of the platform the player can not move what so ever. Below you will see my code. Any help will be appreciated. using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerMovment : MonoBehaviour {
public float speed = 10f;
public Rigidbody rb;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate () {
// Below is player movment
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(h,0f,v);
rb.AddForce(movement * speed);
}
// Hooks player up to plat form after hook up player can not move on own
private void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "plat")
{
transform.parent = other.transform;
}
}
// see if the player left the trigger
private void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "plat")
{
transform.parent = null;
}
}
}
Comment
Answer by PERFKNIGHT · Jul 19, 2017 at 01:45 AM
I don't think that using children and parents is the best solution here. Can you give me some more context?