RK4 in 2D gravity simulation probs - actionscript-3

In actionscript 3.0, I have two objects (a central red star and a orbiting blue planet). I want to use RK4 to plot the orbit. I'm running the simulation once per frame, and drawing once per frame. I have to relate the position of the blue planet in x,y to the central planet so I may be getting lost in the conversion somewhere. This is just for the 1,1 quadrant. I will be adjusting the gravity vector as the blue planet crosses from quadrant to quadrant.
PROBLEM: If I alter the time step, the orbit changes drastically. At small time steps, the orbit becomes a straight line. At large time steps, the orbit becomes tighter. The cooefficients for computing the acceleration for each "K" are not being scaled by dt (except for it being passed through the previous velocity vector).
Here is the RK4 code snip:
http://pastebin.com/Ee6HzBQ2

Related

Tensorflow js reinforcement pong AI does not learn

I'm trying to alter this tensorflow js reinforcement example to let the AI learn the classic pong game in my own project. They both are very similar. Instead of moving left or right in the cart example I move the left paddle up or down while the right paddle is controlled by a simple algorithm following the ball's y coordinate.
My input state tensor consists of:
left paddle y coordinates normalized
ball's y coordinate normalized
ball's x velocity between -1 and 1
ball's y velocity between -1 and 1
Output is a single neuron with the probability of moving left (and inverse probability of moving right).
Each survived step gives a reward of 1 and after the ball moves out of bounds or after max 500 steps the game is reset. Rewards are discounted at the end.
But while the cart example already shows very nice results after around 50 iterations, in my example the paddle mostly stays on one side without moving after 200 iterations.
I tried already different hidden layer sizes like (64,32) or even (128, 256, 128), different activation functions (elu, sigmoid) and just using the paddle y and ball y corrdinates. But I don't see any improvements.
Any ideas how I can improve the learning rate?

Why do convolutional deep learning models produce different FPS for different scenes?

I have a model that inputs image (448x448) and outputs steering angle. As my observation, FPS (frame per second) of system varies depending on the image scene. For example, if image input is a rainy scene, system outputs predictions in 20 FPS. However if image input is sunny scene, system outputs predictions in 30FPS. And complexity of image is effecting FPS too.
Why do the FPS of predictions ​​change depending on the scene conditions, even though the same calculations are made for each picture in the CNNs? What could be the reason of this difference?
I expect same FPS from CNN model for every image input. But it is not stable.

Voxel circles using a noise function

I'm creating a 2D space game where the map is made up of square tiles. I would like a noise function that I can use to generate circular planet, by circular planets I mean 'circles' made out of squares (basically like a circle in Minecraft). The planet's radius should be of all different sizes. The reason I want to use noise is that I want the user to be able to generate a map with a seed so they can generate the same planets again. (the planets should be randomly distributed, not uniformly spaced) How would I implement this using noise so that it procedurally generates?
Place randomly positioned points (circle center)
Then using the same seed generate variable circle radius
To get 'voxels' cut the circle into a grid using division ...
This should do the trick.

How to have accurate collisions in Flash CS6 (AS3)

i am creating an endless runner game and the player as to jump over an obstacle, and if he touches it he looses health. The current collision code is this:
if (man_mc.hitTestObject(crate_mc)) {
health--;
health_txt.text=health.toString();
which is inside a loop. But the problem is that my obstacles are triangles, so when you jump over them if you touch the 'hit box' or dimensions of the triangle you loose health. So how do i make it so the collision is only true if my player is touching the triangle. (and the triangle is a png with transparent background)
EDIT: I found that i could use hitTestPoint instead of hitTestObject but how do i know what co ordinates to put into the parameters?
I would abandon the use of hitTestObject() (or even hitTestPoint()) for collision detection. Instead, I'd use another algorithm for collision detection in your game
I'll assume your player is a (pretty) skinny box and you said that your obstacles are triangles. I'd first try using a basic method of checking if any of the triangle's points are within the player's bounding box. If it is, then you have a collision.
You could also go the other way and check if a player's points in the bounding box are within any triangle, but you may end up with an odd case where a triangle is poking in to the player, but none of the player's points are within the triangle (which can happen if a player gets a triangle right up between the legs >.> ). Also, by going triangle first, there are less points to check per player and triangle pair.
Note that using this simple method won't tell you how much intersection there is, but I'm guessing you may not need that, since you were using the hitTestObject() method before.
Following my comment
I won't write the code for you line by line, but it's pretty easy to figure it out. So I'll describe one method:
Let's say your player is a rectangle that is 50px wide by 100px tall and the center of the player rectangle is set as the player's position. Half the width of the player is 25px and half the height is 50px.
So if the player is at say 240, 370 (a random spot I made up on screen), then to check if a point falls within you'd check if the x point is within 215 to 265 (240 +/- 25px) and if it is, then you'd check if the y point is within 320 and 420 (370 +/- 50px). If both these conditions are true, then the point is either touching or within the player box (so there is a collision). If any of them are false then the point is not (you could stop checking if the first condition is false, saving you a extra check operation).
Once you have that working (a point vs box test), then you'd just run a triangle's points through it to see if the triangle is intersecting the player box. How you get your triangle's points would vary based on your triangles.

Box2D, libGDX slope collision

I have created a Box2D based map for my platformer using ChainShape which has different angle slopes (no more than 45°).
My problem is the slope collision with my player. The player' body has 2 fixtures, a rectangle and a circle below it. Whenever I move the player (the method doesn't matter the results are the same) and I stop on the middle of a slope I slowly glide down. I managed to temporarily fix that but the main reason for this post is the fact that whenever I leave a slope l I shoot out because I still have some impulse left from the previous movement. Same thing happens when I enter a downwards slope, or when I stop on a slope and I start moving again.
Entering / leaving the slope:
(The red lines are the desired movement, the black is the movement I have right now)
Start moving on a slope:
(The red lines are the desired movement, the black is the movement I have right now)
Could you please help me out with this problem? I don't mind if your answer is detailed either.
I've found the easiest way to stop the character sliding on a slope is to set the bodies linear dampening to Infinity when they player releases the move button and the body is grounded, which I'm using ray tracing to test for.
As for your issues with the character not following the slopes, this is simply due to momentum. When you reach the top of the slope, your body still has a some upward momentum which it has to clear. Same as when you're approaching a downward slope - your body still has some horizontal momentum to clear. I've had some success with ray tracing to find the normal of the slope below the player's position, and manually setting the body's velocity to match the tangent, however this not be applicable in your application.
As for your second issue, with starting movement on a slope, I expect you are applying a direct horizontal impulse, which is throwing the body off the slope. Again this could be rectified by finding the gradient of the slope where the player is standing, and applying the force at the appropriate angle.