How to make a a ball move (left or right only) by press a button on the screen. I need a code for this one.
Thank you
How to make a a ball move (left or right only) by press a button on the screen. I need a code for this one.
Thank you
Look up RididBody.AddForce in the docs.
I know about this. I made it before with roll a ball.
The game i work on it now is 3d world but 2d style.
I want the ball to move at X line (vertical) not Z or Y line.
I made some codes but didn’t work.
AddForce isn’t quite precise enough to be absolutely sure of a given direction on its own, or rather physics in general (even pseudo-physics) is too messy for that on its own. That said, you can still use AddForce to supply the force to drive the object in the given direction easily enough, and precisely, you just have to constrain the Y and Z axis using Rigidbody Constraints, or by simply overwriting the X and Z values of the transform.position for the sphere every frame. It’s up to you- people do both pretty commonly. Look at the example on the AddForce page to get an idea of how it works and how to write it.