Hi,
with Unity 2.6.1 trail version, I’m trying re-program “Arkanoid” style game…
move Arkanoid with moving mouse right and left
Left Click: start push the ball
here is my start try:
http://iammfa.webs.com/arkanoid.html
The problem here: you can see the ball jumping a little when moving … I want the ball moves in X and Z directions and disable Y direction, how can I do that?
here is the ball code:
//define some variables
var speed=20;
var colliding : Collider;
var body : Rigidbody;
var forceMultiplier = 25;
//define some objects
var childTransform : Transform;
var parentTransform : Transform;
//define some boolean variables
var stick:boolean=true;
var ballMove:boolean=false;
function FixedUpdate (){
//how many seconds since scene started
var seconds=Time.timeSinceLevelLoad;
//as long as stick variable true, stick ball to arkanoid
if(stick){
childTransform.transform.parent = parentTransform.transform;
}else{
childTransform.transform.parent = null;
}
//is player press space or scene started since 2 seconds
if(Input.GetMouseButton(0) || seconds==2){
stick=false;
ballMove=true;
//ballMove variable be true, move ball to ward top right corner
if(ballMove){
rigidbody.velocity.z=speed;
rigidbody.velocity.x=-speed;
}
}
}
function OnCollisionEnter (collisionInfo : Collision) {
if (collisionInfo.gameObject.name == "PinBall") {
var contactNormal = collisionInfo.contacts[0];
var rot = Quaternion.FromToRotation(Vector3.up, contactNormal.normal);
var pos = contactNormal.point;
var rv = collisionInfo.relativeVelocity.magnitude;
direction = body.transform.position - pos;
reflectBallTo = Vector3.Reflect (pos, direction);
colliding.gameObject.rigidbody.AddForce (reflectBallTo * forceMultiplier);
}
}