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
- I need the BIRT.war that is compatible with Java 17 and Tomcat 10
- Creating global Class holder
- No method found for class java.lang.String in Kafka
- Issue edit a jtable with a pictures
- getting error when trying to launch kotlin jar file that use supabase "java.lang.NoClassDefFoundError"
- Does the && (logical AND) operator have a higher precedence than || (logical OR) operator in Java?
- Mixed color rendering in a JTable
- HTTPS configuration in Spring Boot, server returning timeout
- How to use Layout to create textfields which dont increase in size?
- Function for making the code wait in javafx
- How to create beans of the same class for multiple template parameters in Spring
- How could you print a specific String from an array with the values of an array from a double array on the same line, using iteration to print all?
- org.telegram.telegrambots.meta.exceptions.TelegramApiException: Bot token and username can't be empty
- Accessing Secret Variables in Classic Pipelines through Java app in Azure DevOps
- Postgres && statement Error in Mybatis Mapper?
Related Questions in PHYSICS
- How to throw a charged particle in a electric vector field?
- How can I lock a rigidbody's rotation on all axis? Bullet Physics
- Read Access Violation when accessing a QBarDataItem in a loop in QLineEdit::editingFinished
- Is there a range of launch velocities that would get my satellite as close to Mars as possible?
- Unity Distance Joint2D seemingly breaking for no reason
- Coding Runge-Kutta 4 in C++ for a Force proportional to 1/r^2 outputs a trajectory different from scipy.optimise.solve_ivp
- Runge Kutta implementation is less accurate than Euler implementation
- How do I simulate a vector field from the Boit-Savart law for a coil?
- Lomb-Scargle Method to Model the Rotation Signal Giving a Straight Line Instead of Modelling
- Solving ODE pendulum system with C and the GSL libary yields erroneous results for part of the answer then is correct
- Python script becomes unresponsive at 100% CPU usage (single core)
- How to Color the Area Above the Curve in Gnuplot?
- How to make a Unity 2D hinge joint that springs to a given angle?
- Jump height and Gravity not consistent with fluctuating FPS (flappybird-like Javascript minigame)
- I have a problem with coding a Diffusion equation (FT-CS method)
Related Questions in GAME-PHYSICS
- How would I code player jump physics, similar to "soccer physics", and make players collide with a ball in pygame?
- AI and Game physics
- How do I detect for collisions without immediately resolving them in Godot 3D?
- How to find the rotation of a quaternion along each of the 3 axes separately?
- Unity's HingeJoints: Door changes starting Position and AngleLimits on play mode
- Paddle and Ball Sync Problem in Multiplayer Air Hockey in Godot
- Movement value is reset before it can get cancelled by a UnityEvent
- How to make two kinematic objects in Unity detect overlap?
- Jump height and Gravity not consistent with fluctuating FPS (flappybird-like Javascript minigame)
- Game Collision Detection - Separating Axis Theorem Collision Resolution Issue
- Aligning mesh to a dynamic rapier 3D rigidbody
- Player looks like teleporting instead of moving smoothly when camera damping is enabled GODOT
- Collision Detection works only with two objects
- This Unity Jumping & Gravity script is a mess, how can I fix it?
- Grappling/Swinging System in Godot 4 3D
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 # Hahtags
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