Hi,
I am working on my first Unity game, a Pong clone.
I have utilised some of the in built features to get the main game working although I am having trouble with the ball deflecting at an angle off the paddle unless it hits the edge. When it hits the flat face of the object it just deflects horizontally across the x plane.
The ball is a rigidbody which hits box colliders on the paddles. The ball has one script and the verticalcontroller script manages the paddles.
Also there is no gravity, angular drag or friction enabled.
using UnityEngine;
using System.Collections;
public class Ball : MonoBehaviour {
private const float velocityIncrement = 1.0f;
void Start() {
Reset();
}
void OnTriggerEnter(){
Reset();
}
void Update()
{
//rigidbody.AddForce(10, 10, 0, ForceMode.Impulse);
rigidbody.velocity *= velocityIncrement;
}
private void Reset()
{
transform.position = Vector3.zero;
rigidbody.velocity = new Vector3 (80,1,0);
//rigidbody.angularVelocity = new Vector3 (0,10,0);
}
}
using UnityEngine;
using System.Collections;
public class VerticalController : MonoBehaviour {
public string axisName = "Vertical";
public float speed = .5f;
// Update is called once per frame
void Update () {
var delta = new Vector3(0,speed,0);
if (Input.GetAxis(axisName) >= .001)
delta *= 1f;
else if (Input.GetAxis(axisName) <= -.001)
delta *= -1f;
else
delta = Vector3.zero;
transform.position += delta;
}
}