# Thread: Help me with maths on my program!

1. Member
Join Date
Feb 2011
Posts
19
Rep Power
0

## Help me with maths on my program!

Hello, i am in need of help with doing some calculations on my program. I am not really in all the math functions but i want to learn the way how can i calculate the right x and y speed for ball to go on correct angle. like if ball's y speed was 1 it would go just up. (0°) Actually i want the ball go in the direction of certain position to mouse's position. Can anyone help me with this, i found much similar stuff to this but not well explained. Heres example: YouTube - Little Java game also theres source for the code used but its commented in norway and the maker havent responsed yet. Can you guys please help me with this?

2. Have you actually attempted to write any code for this?

Goldest

3. Senior Member
Join Date
Aug 2008
Location
Stockholm, Sweden
Posts
119
Rep Power
0
This isn't a coding factory and I seriously doubt anyone's gonna visit several external sites checking someone else's(!!!) code when you haven't even tried for yourself first.

Come back when you have own attempts to show us. Although I get a strong feeling you have no idea how to even begin, which means you're in way over your head. Feel free to prove me wrong.

4. Member
Join Date
Feb 2011
Posts
19
Rep Power
0
This was not about managing to do it, i want to learn the way how to do it. I did it with the help of the code from the video i linked and it works, but now i want to figure out why it works, where do i need squareroot of distances and so on. I show you the code and please explain the calculation part for me if you're such kind person! :)
Java | import java.awt.Dimension; import java.awt.Graphi - BallTest

5. If you are concerned about what happens inside the sqrt method of Math class, then it's just a static method which takes the parameter and returns the positive square root of it. Have a look at Math.sqrt(double d) documentation.

If you are starting along the path of Java, I would strongly recommend you to have a look at the Java API documentation provided here: Java 6 API

There would be many things along the way, that you might not understand and going through documentation will help you out.

Best of luck,

Goldest

6. Member
Join Date
Feb 2011
Posts
19
Rep Power
0
I am wondering how i can get the right and x and y speed throught the sqrt of distances between 2 objects ;o

7. Member
Join Date
Feb 2011
Posts
19
Rep Power
0
cmon, please help me, i am stucking on that :(

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•