# How can I Implement spin in billiard game?

I'm not sure that you played billiard or snooker before.if you played you should know about spin. but anyway if you don't know about it you can see it in this video

I want to Implement spin like this game

for example difference between Top spin and Back spin is:

Top spin

Back spin

Spin behaviour

if you aim behind the ball you can shoot the ball in all direction

if you aim closest to right you can just aim the right

if you aim closest to left you can just aim the left

I found a same Issue that used Torque in stackoverflow but I don't know why didn't work!

Top Spin

GetComponent<Rigidbody>().AddTorque(Vector3.back * cueStrength );


Back Spin

GetComponent<Rigidbody>().AddTorque(Vector3.forward * cueStrength );


# Update

What I tried

I add joystick to select spin angle

then I apply spin force ( It seems my spin works but sometimes didn't work that I attached video in end of my question).

this is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MainBall : MonoBehaviour {

private Vector3 FirstPos; // store first position as reset position
public Transform SpinRoator; // spin rotator cylinder that show spin angle
private Rigidbody rigidbody;
public bool SpinUsed; // spin should use once
private float v2;

private void Start() {
rigidbody = GetComponent<Rigidbody>();
FirstPos = transform.position;
}

//After goal reset ball position
public void ResetPos(){
rigidbody.velocity = Vector3.zero;
rigidbody.angularVelocity = Vector3.zero;
transform.position = FirstPos;

}

void SpinForce(){
SpinUsed = true;
float F = ComebackForce(); // calculate comeback force
StopBall(); // stop ball
}

// calculating return force 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;
}

//stop ball
public void StopBall(){
rigidbody.velocity = Vector3.zero;
rigidbody.angularVelocity = Vector3.zero;
}

private void OnCollisionEnter(Collision other) {
if(other.collider.tag == "Ball" || other.collider.tag == "ColorfulBall"){
if(!SpinUsed){
SpinForce();
}
}
}
}


# but What is Problem?!

It seems works correctly but My Problem is sometimes Spin don't work correctly you can see this video that demonstrate this problem.my ball goes wrong direction of spin!!!

1.Ball goes Wrong sometimes

as you can see in above gif ball goes wrong direction!!! ball should go along yellow cylinder but I don't know what is problem of my code!!!

1.Ball goes slow sometimes

another problem is comeback force is slow sometimes!!! I calculate comeback force F = m.a but why is it slow?!

• The Unity physics engine is good enough for most games, but if you want to develop a game where it is extremely important to get the physics exactly right, like a billard simulation for example, you might have to write your own physics. Mar 12, 2019 at 10:38
• @Philipp I don't know how can I Implement custom physic.but I think it's possible to recreate Spins with default physic.but anyway I hope someone help me to Implement custom physic for billiard Apr 10, 2019 at 17:27
• This question is too broad. We could help if you had a system already working and needed assistance with specific issues. Rocket League, for example, used Bullet physics: en.wikipedia.org/wiki/Bullet_(software)
– Almo
Apr 10, 2019 at 18:37
• @Almo why should I use Bullet physic? Is there a problem in unity built-in physic problem? Apr 11, 2019 at 3:30
• I'm not going to do research for you. A quick google searched turned this up. rockpapershotgun.com/2015/09/02/rocket-league-making-of
– Almo
Apr 11, 2019 at 15:30

• Can you explain how this is different from the AddForceAtPosition(...) solution that OP already attempted? Apr 10, 2019 at 19:05