I'm trying to make a Brick Breaker game in Java and I want my ball to have a curved trajectory, based on paddle's acceleration (no gravity involved). How can I compute the ball position at a given moment? I think I need to compute the velocity first but i can't figure out how to do this.
Curved Trajectory for a 2D game in Java
560 Views Asked by user3801593 At
1
There are 1 best solutions below
Related Questions in JAVA
- Add image to JCheckBoxMenuItem
- How to access invisible Unordered List element with Selenium WebDriver using Java
- Inheritance in Java, apparent type vs actual type
- Java catch the ball Game
- Access objects variable & method by name
- GridBagLayout is displaying JTextField and JTextArea as short, vertical lines
- Perform a task each interval
- Compound classes stored in an array are not accessible in selenium java
- How to avoid concurrent access to a resource?
- Why does processing goes slower on implementing try catch block in java?
- Redirect inside java interceptor
- Push toolbar content below statusbar
- Animation in Java on top of JPanel
- JPA - How to query with a LIKE operator in combination with an AttributeConverter
- Java Assign a Value to an array cell
Related Questions in PHYSICS
- Calculate energy for each frequency band around frequency F of interest in Python
- sampling 2-dimensional surface: how many sample points along X & Y axes?
- How do I make a decaying oscilating function in python?
- Make two physics objects not collide but do detect collisions in Unity
- Bounce a ball from one point to another - Vector and Acceleration
- cocos2d-x physics nodes slide along other
- trouble getting collision point
- Python pendulum
- Best language for battery modelling?
- Tracing out the motion of a double pendulum in gnuplot (and gif conversion)?
- Parallelizing pairwise gravitational force calculation with OpenMP in Fortran 90
- Scenekit PhysicEngine follow rolling ball
- 2D orbital Physics model showing strange behaviour
- Verlet / Euler Integration is inaccurate
- Which Box2D-like physics engine parameters need pixel conversion?
Related Questions in GAME-PHYSICS
- Create polygon from grid (for collisions)
- timing issues while creating replay of game (ghost for racing)
- Bullet not shooting next to my spaceship sprite(LIbgdx)
- How can I prevent picture boxes from intersecting, while they are in constant movement?
- How to shoot infinite bullets in game coded in Python?
- Bounce a ball from one point to another - Vector and Acceleration
- Box doesn't roll in Bullet Physics
- How to calculate the time it takes to reach terminal velocity under constant acceleration?
- Are multiple didBeginContact calls called simultaneously?
- 2D Collision response - rotating, moving polygon hitting a wall
- Constant Velocity Jitters in SpriteKit
- SpriteKit - add border with SKView
- AS3 AI barrier detection and movement
- Java 2D Platformer Gravity
- 2D orbital Physics model showing strange behaviour
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
The Spinning ball's path.
Curved trajectory? Do you mean when you hit the ball you add spin to the ball and then that spin causes the ball to curve through the air?
If so then use the following method.
The ball needs the following properties
And a bat
When the ball hits the bat do the normal reflection.
To convert the bats sideways movement into ball rotation just needs the ball's radius (for the most simple method) Assuming that the bat is at bottom of screen.
The amount of spin is related to the ball sideways motion relative to the bat, then divided by the radius to give the change in rotation per frame. Add that to the ball's current rotation
We are not going to do a full fluid dynamic simulation but rather an approximation.
Magnus effect
When a ball moving through the air, is spinning, one side of the ball moves forward in the air stream (outside), and the other side move in the opposite direction (inside). The imbalance in airflow over the surface and the way the inside spin pulls the air with it causes a low pressure region on the inside in the direction perpendicular to the ball's motion.
The force applied by this low pressure area is spread over the ball's diameter
We don't need all of this. Air density is fixed as is the ball radius. Thus the force is a linear relationship between ball velocity and ball spin rate. The rest can be set as a coefficient value we can call spinCof
The force adds acceleration which is dependent on mass. Again this does not change so we can add that to the spinCof value.
So the final formula is
The value of spinCof is unknown and you will need to experiment to find a value that is playable.
To do this in code
And that is it.
And quick example of this in practice