
[ad_1]
I’m unsure that you simply performed billiard or snooker earlier than.for those who performed it is 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 recreation
for instance distinction between Top spin and Back spin is:
Spin behaviour
for those who goal behind the ball you’ll be able to shoot the ball in all course
for those who goal closest to proper you’ll be able to simply goal the proper
for those who goal closest to left you’ll be able to simply goal the left
I discovered a identical Issue that used Torque in stackoverflow however I do not know why did not work!
Top Spin
GetComponent<Rigidbody>().AddTorque(Vector3.again * cueStrength );
GetComponent<Rigidbody>().AddForceAtPosition(cueStick.ahead * cueStrength,remodel.place,ForceMode.Acceleration);
Back Spin
GetComponent<Rigidbody>().AddTorque(Vector3.ahead * cueStrength );
GetComponent<Rigidbody>().AddForceAtPosition(cueStick.ahead * cueStrength,remodel.place,ForceMode.Acceleration);
I observed that flyordie’s snooker did not use AddTorque.so I do not want reply that Implemented 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 connected video in finish of my query).
that is my code:
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
public class PrimaryBall : MonoBehaviour {
non-public Vector3 FirstPos; // retailer first place as reset place
public Transform 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 Start() {
rigidbody = GetComponent<Rigidbody>();
FirstPos = remodel.place;
}
//After aim reset ball place
public void ResetPos(){
rigidbody.velocity = Vector3.zero;
rigidbody.angularVelocity = Vector3.zero;
remodel.place = FirstPos;
}
void SpinPressure(){
SpinUsed = true;
float F = ComebackForce(); // calculate comeback power
CeaseBall(); // 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 CeaseBall(){
rigidbody.velocity = Vector3.zero;
rigidbody.angularVelocity = Vector3.zero;
}
non-public void OnCollisionEnter(Collision different) {
if(different.collider.tag == "Ball" || different.collider.tag == "ColourfulBall"){
if(!SpinUsed){
SpinPressure();
}
}
}
}
It appears works accurately however My Problem is typically Spin do not work accurately you’ll be able to see this video that show this downside.my ball goes flawed course of spin!!!
1.Ball goes Wrong 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 gradual generally
one other downside is comeback power is gradual generally!!!
I calculate comeback power F = m.a
however why is it gradual?!
[ad_2]