- Home /
Paddle which control by Cpu for Air hockey game Raycasting issue
Hello, I am making a Air Hockey game but another paddle which will be control by a CPU i am facing problem. Actually i am applying Ray-casting, Ray, Trigger Enter or Collision but it is not working smoothely ...What should i apply on paddle then it works fine.... I want to make this game Smooth...Anyone please suggest me what should i do for smoothness??
If you could post the code you are currently using, I would be happy to help out - but I will need a little more information first.
Exactly what kind of behavior are you trying to achieve with the paddle? Do you want it to follow the air hockey puck? Hit the puck back to the player? What do you mean by "smooth"?
Answer by VIPINSIRWANI · Jul 11, 2013 at 10:30 AM
void Update () { pos2 = new Vector3(puck.transform.position.x,0.3359161f,puck.transform.position.z); newpos = new Vector3(0.2534024f,0.3359161f,puck.transform.position.z); transform.position = Vector3.Lerp(transform.position,newpos,(smooth*Time.deltaTime));
if(puck.transform.position.x > -0.1068026)
{
transform.position = Vector3.Lerp(transform.position,pos2,(smooth * Time.deltaTime));
}
if(transform.position.x < -0.02968476)
{
transform.position = new Vector3(-0.02968476f,0.3359161f,transform.position.z);
}
Vector3 fwd = transform.TransformDirection(Vector3.right);
if(Physics.Raycast(transform.position,backR,out hit,0.5f)) { if(hit.transform.gameObject.tag == "Puck") { Debug.DrawRay(transform.position,backR,Color.black);
// Debug.Log("Back Left.."); /FRONT = false; BACK = false; LEFT = false; RIGHT = false; flag = false; FRONTL = false; FRONTR = false; BACKR = false; BACKL = true;/ flag = true; } else { flag = false;
} }
//Raycasting in all direction and void FixedUpdate() { if(flag) { //puck.rigidbody.AddForce(transform.position.x,transform.position.y,transform.position.z); //transform.Translate(newpos*Time.deltaTime); Debug.Log("Flag value is true..."); transform.position = Vector3.Lerp(transform.position,newpos, trans * Time.deltaTime); } Here the Smoothness means everything is happening very fast...
Please format properly using "code sample" button.
It will make the process a whole lot easier, as when I was reformatting your code it looked like there were a few things missing... just want to make sure it wasn't because of formatting. :-)
Your answer
Follow this Question
Related Questions
Paddle which control by Cpu for Air hockey game 0 Answers
raycast not colliding 1 Answer
Colliders on mecanim animal. 0 Answers
Multiple hit detection with Raycasting? 2 Answers
Raycast not hitting collider 2 Answers