I am unsure that you just performed billiard or snooker earlier than.in case you performed it’s best to learn about spin.
however anyway if you do not know about it you’ll be able to see it in this video
I wish to Implement spin like this sport
for instance distinction between Prime spin and Again spin is:
Spin behaviour
in case you goal behind the ball you’ll be able to shoot the ball in all course
in case you goal closest to proper you’ll be able to simply goal the correct
in case you goal closest to left you’ll be able to simply goal the left
I discovered a similar Challenge that used Torque in stackoverflow however I do not know why did not work!
Prime Spin
GetComponent().AddTorque(Vector3.again * cueStrength );
GetComponent().AddForceAtPosition(cueStick.ahead * cueStrength,rework.place,ForceMode.Acceleration);
Again Spin
GetComponent().AddTorque(Vector3.ahead * cueStrength );
GetComponent().AddForceAtPosition(cueStick.ahead * cueStrength,rework.place,ForceMode.Acceleration);
I seen that flyordie’s snooker did not use AddTorque.so I do not want reply that Applied with AddTorque.
What I attempted
I add joystick to pick out spin angle
then I apply spin power ( It appears my spin works however generally did not work that I hooked up video in finish of my query).
that is my code:
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
public class MainBall : MonoBehaviour {
non-public Vector3 FirstPos; // retailer first place as reset place
public Remodel SpinRoator; // spin rotator cylinder that present spin angle
non-public Rigidbody rigidbody;
public bool SpinUsed; // spin ought to use as soon as
non-public float v2;
non-public void Begin() {
rigidbody = GetComponent();
FirstPos = rework.place;
}
//After objective reset ball place
public void ResetPos(){
rigidbody.velocity = Vector3.zero;
rigidbody.angularVelocity = Vector3.zero;
rework.place = FirstPos;
}
void SpinForce(){
SpinUsed = true;
float F = ComebackForce(); // calculate comeback power
StopBall(); // cease ball
rigidbody.AddForce(SpinRoator.ahead*F);// apply spin power
}
// calculating return power after hitting f = m.a
float ComebackForce(){
var m = rigidbody.mass;
var v1 = rigidbody.velocity.magnitude;
var a = (v1 - v2) / Time.deltaTime;
var F = m * a;
v2 = rigidbody.velocity.magnitude;
return F;
}
//cease ball
public void StopBall(){
rigidbody.velocity = Vector3.zero;
rigidbody.angularVelocity = Vector3.zero;
}
non-public void OnCollisionEnter(Collision different) {
if(different.collider.tag == "Ball" || different.collider.tag == "ColorfulBall"){
if(!SpinUsed){
SpinForce();
}
}
}
}
It appears works appropriately however My Drawback is typically Spin do not work appropriately you’ll be able to see this video that exhibit this downside.my ball goes flawed course of spin!!!
1.Ball goes Improper generally
as you’ll be able to see in above gif ball goes flawed course!!! ball ought to go alongside yellow cylinder however I do not know what’s downside of my code!!!
1.Ball goes sluggish generally
one other downside is comeback power is sluggish generally!!!
I calculate comeback power F = m.a
however why is it sluggish?!