So I’m creating a 2D pong game, and I’d like to implement a spin to the ball whenever the player, for example moves down, creating back spin. Or if the player moves up, creating top spin.
And if the ball had some top spin to it, and it hit the other player( who wasn’t moving ) then I’d like for it to move in the up direction, opposite with backspin.
Another thing I’d like to implement would be, if the ball had topspin creating, I’d like for it to keep on getting more and more spin if both the players allow it to spin the same direction.
I haven’t got much code on this as I have no idea how I would implement this, I’ve tried messing around with rigidbody2D.rotation
but it doesn’t seem to affect much as I’m not completely sure on how to use this.
A game that does this type of physics well, is Sports Heads: Football (This is for reference if someone isn’t sure what I mean)
This is the only bit of code I have concerning the player and ball’s interaction.
function OnCollisionEnter2D (colInfo : Collision2D) {
if(colInfo.collider.tag == "Player") {
//The velocity of the ball is, the player's velocity/2 + the ball's velocity/3;
rigidbody2D.velocity.y = rigidbody2D.velocity.y/2 + colInfo.collider.rigidbody2D.velocity.y/3;
audio.pitch = Random.Range(0.8f, 1.2f);
audio.Play();
}
}