Hi! I am currently working on a tilt/maze Game. the platform movement code comes from this post:Tilting Platform Question - Questions & Answers - Unity Discussions
and it looks currently like this:
as you can see, i have 2 problems:
- the blob shadow is not moving with the platform and disappears sometimes under the platform
- and the Ball/Sphere also does not stick to the Ground and sometimes flies in the air
the blob shadow script looks like this:
using UnityEngine;
using System.Collections;
public class BallFollow : MonoBehaviour {
Transform bar;
void Start() {
bar = GameObject.Find("Ball").transform;
}
void Update() {
transform.position = new Vector3(bar.position.x, transform.position.y, bar.position.z);
}
}
so it just copies the position of the ball, but somehow has also needs to copy the rotation of the platform?
and then, the ball movement script looks like this:
sing UnityEngine;
using System.Collections;
namespace qtools.qmaze.example
{
public class QBallController : MonoBehaviour
{
public float moveScaleX = 1.0f;
public float moveScaleY = 1.0f;
public float moveMaxSpeed = 1.0f;
public float moveLerp = 0.9f;
private Rigidbody rigidBody;
void Start ()
{
rigidBody = GetComponent<Rigidbody>();
}
void Update ()
{
Vector3 velocity = (Vector3.forward * Input.GetAxis("Horizontal") * moveScaleX);
velocity+= (Vector3.left * Input.GetAxis("Vertical") * moveScaleY);
velocity = Vector3.ClampMagnitude(velocity, moveMaxSpeed);
velocity *= moveLerp;
rigidBody.velocity = velocity;
}
}
}
normally it would be enough to give the ball a rigidbody and control the ball by tilting the platform he is lying on.
but, i used this ball script because if i wouldn’t , the ball would move to slowly over the platform. so i am controlling the platform AND the Ball. but i need a way to let the ball stick to the platform. the rigidbody settings of the ball are: mass:1 - drag:0 - angular Drag: 0.7 and the physic settings are untouched.
Thanks for your help upfront!