So in my jumping game i want moving plattforms :
Now the plattforms work fine on their own, their iteraction with the player is wierd though in 2 situations:
if the player is below the plattform, he doesnt get pushed away/ “crashed”. Instead the plattform moves through the player. Adding a rigidbody to the plattform makes it worse, because then the player even starts to push the plattform away instead of the other way around. How can i have the plattform push the player away from beeing underneath?
if the plattform goes in a direction other than the y-axis and the player is ON the plattform. The player isnt moved along with the plattform. So he kind a has to run to stay on the moving plattform. How can i make the player move with the plattform in all 3 axis?
Here the moving plattform code, not sure if it’s of any help for answering my question though.
using UnityEngine;
using System.Collections;
public class MovingAB : MonoBehaviour {
public float x = 0;
public float y = 0;
public float z = 0;
public float offset = 0; //percent done going to B
public float speed = 2;
Vector3 PointA;
Vector3 PointB;
Vector3 direction;
float way;
float wayDone =0;
bool gotoB = true;
// Use this for initialization
void Start () {
PointA = transform.position;
PointB = PointA + new Vector3 (x, y, z);
direction = (PointB - PointA).normalized;
way = (PointB - PointA).magnitude;
transform.position += offset *way/100 * direction;
wayDone += offset* way/100;
}
// Update is called once per frame
void Update () {
if (gotoB) {
transform.position += direction * speed * Time.deltaTime;
wayDone += speed * Time.deltaTime;
} else {
transform.position -= direction*speed*Time.deltaTime;
wayDone += speed * Time.deltaTime;
}
//check if reached pointA or B and reverses direction
if (wayDone >= way) {
gotoB = !gotoB;
wayDone -= way;
}
}
}