Code Monkey home page Code Monkey logo

basketball's People

Contributors

yonimal676 avatar

Stargazers

 avatar

Watchers

 avatar

basketball's Issues

finger drag outside of radius

level of difficulty: 3/5

Here is a general representation of the problem:

image

steps:

1. when distance between T and i is bigger than a fixed size -

2. figure out the angle, better yet the radian between T (touched point) and i and the point straight line that crosses the circle horizontally.

3. then find the sizes of the adjacent and opposite sides of the triangle in the circle by finding: cos/sin(radian)max_radius

4. then, depending on which quarter we are talking about, I will either subtract or add , opposite to Yi and adjacent to Xi to get P(x, y) and also keep in mind the width/2f and height/2f so that the coordinates of P are exactly the middle of the ball.

physics

Originally posted by yonimal676 October 11, 2022
image

great visualizer:
https://ophysics.com/k8.html

Note: it doesn't matter what the weight of the object is, it will fall the same

image
image

HOLY SHIT IT WORKS

I figured how to run the time for the ball in GameView -> sleep() and then the formulas worked.

This is a revisit: even though it worked, it looked weird:

image

This is how it looks now:
image

This was done with the help of chatGPT, i'm speechless.

Now that the physics calculations are refined, I can continue in Collision Physics #26 -> Changing Direction #34

FEATURE:

public void physicsUpdateNoCol(float time)

most of the times, the time parameter is going to be ball.time, how ever I will add this parameter in case i want to calculate the next X/Y.

weird physics bug

image

This happens when the ball is shot at the approximate angle of -177 degrees

previously it looked like this:
image
with this formula (v0y is minus because of the inverted Y axis):
ball.vy = - ball.v0y - (ball.GRAVITY * time);

but now the code is:

        if (quarterOfLaunch == 1 || quarterOfLaunch == 2) // throwing the ball downwards.
            ball.vy = ball.v0y - (ball.GRAVITY * time);  // the vertical velocity changes constantly.
        else 
            ball.vy = ball.v0y + (ball.GRAVITY * time);

After playing with the physics for a bit, this is the current state:

image

Basically what happens when the ball changes its' trajectory is that the VY reaches 0 after being minus (-1) and then flips to positive (1) as it should, but the velocity-changing system flips the number when it reaches max height.

Here's the solotion:
image

Calculate Vy after the system.

Collision Physics

There are 3 types of collisions:

  1. right wall
  2. floor
  3. left wall

But first, I must figure out how to change the direction of the ball after thrown:

Discussion: Changing Direction #34

image

1. right wall

premise:

Untitled
11111

Attributes:

  1. velocityX = -1 * Math.abs(velocityX);

image
image

1. left wall

premise:

22222

1. floor

premise:

333333
444444

combined:

5555

where do i even start??

correcting the line with the ball

The issue: we don't want to draw just up to the ball Rect, but to to ball itself:

image

first try:

image

אבל מה עושים במקרה כזה:?

image

Untitled

physics don't work when angle is -90 or 90

This problem is caused from the velocityX being impossibly tiny (7.717558E-5 for example).

so one solution might be setting velocityX to 0 AS IT SHOULD BE when the angle is 90 or -90.

I've tried it and it's not the problem.

Found the source of the bug:

if (ball.velocityY == 0 || ball.x >= ball.range * ball.ratioPXtoM)
                ball.velocityY *= -1;

To be honest i have no idea why it was there in the first place, but that happens sometimes...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.