# Help me with maths on my program!

• 02-16-2011, 03:58 PM
Ruuhkis
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?
• 02-16-2011, 04:37 PM
goldest
Have you actually attempted to write any code for this?

Goldest
• 02-16-2011, 04:40 PM
ojn
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.
• 02-16-2011, 05:11 PM
Ruuhkis
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
• 02-16-2011, 06:42 PM
goldest
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
• 02-16-2011, 06:47 PM
Ruuhkis
I am wondering how i can get the right and x and y speed throught the sqrt of distances between 2 objects ;o
• 02-17-2011, 07:27 AM
Ruuhkis
cmon, please help me, i am stucking on that :(