Deceleration and acceleration - android

Im making an Android game and I'm looking for a relatively simple tutorial on ball collision detection. In particular an elastic collision between 2 balls (That is to say how balls would behave after the collision - kinda like pool balls when they collide).
Also, if anyone knows of an example/ tutorial on deceleration and acceleration I would appreciate it. I'm detecting if 2 balls are in proximity (not colliding yet) with each other. If ball 1 is within a certain radius of a static ball 2, ball 1 will start to decelerate. Once ball 1 reaches another point closer to ball 2, ball 1 will change direction and start accelerating again to its original velocity.
I can detect the first collision and decelerate ball 1, as well as switch its direction, but the acceleration I implemented is not correct.
If someone maybe knows of such an example, can you maybe point me in the right direction?

http://www.euclideanspace.com/physics/dynamics/collision/twod/index.htm
http://www.gamasutra.com/view/feature/3015/pool_hall_lessons_fast_accurate_.php

Related

Preventing body from too high acceleration

I am currently creating an Andengine game which features a ball and a blocker just like pong, except in my game the world and blocker aren't squares and are instead circles.
Right now when the ball bounces off of the blocker all physics seem to check out alright but when I move the blocker really fast to the destination and the blocker hits the ball the ball goes flying off the screen at insane speeds.
How would I go about keeping the ball's velocity at the same speed all the time while keeping current physics?
Don't remember exact code but the logic is:
in onManageedUpdate check the speed of your object, then if speed exceed some value you are happy with set the linear speed to this good value.
Other solution could be that you use ContactListener and in postSolve or endContact you set velocity to desired one.
Also check why this speed after bounce is that fast. Is it because a blocker is moving really fast? Does it also happen when blocker is moving slowly?

Android collision detection accuracy

I have one Sprite and multiple bitmaps that work as bullets. Now the problem is that I want the bullet to go really fast but that again brings a problem to my collision detection function, The way it works is that every frame I create a Rect at both the enemy and the bullet and check for overlaps.
Now if a bullet goes really fast it like "jumps" from point to point and that means if a enemy is small and the bullet "jumped" over the enemy it wouldn't get noticed.
What I wanna know is if there is a way to like detect if a collision is going to happen between 2 moving objects or just look if a enemy is in the trajectory of the bullet.
I made the collision detection by looping through an array of enemies and inside of that for loop I loop all bullets and then create a rect for both and check for collisions with Rect.intersects for each enemy and bullet.
The bullets heading is measured by one fixed point and touch input and then calculated by this function:
public void calcPoint(float x, float y) {
double alfa = Math.atan(x / y);//x and y are inputs
bulletPointX = (float) Math.sin(alfa) * speed;
bulletPointY = (float) Math.cos(alfa) * speed;
}
I have no idea how to fix it and I'd like some adivice how to do it and maby an example...
There are several ways to do this, but the easiest is probably predictive collision detection. Basically, you split the movement into time segments and check for each segment. It may not be very efficient if you have a few thousand objects moving around, but for most cases it'll work just fine.
It's known by a few names, also. The link I gave can help with the basics, but to learn more, do a search for:
Frame Independent Collision Detection
Continuous Collision Detection
Sweep Testing

Bullet movement

I'm new at games development and now stalled at one problem.
Trying to make tower defence type game, For now i have made "tower" with some functions, and where is problem with firing bullets.
Idea: touch somewhere on screen and bullet fire that direction. (bullet starting pos in middle of screen, speed must be a constant)
Maybe somebody knows how to calc that direction which bullet should fire.
I think, should calc angle or something to get that direction...
i.e.
this.mPhysicsHandler.setVelocity(angle*SPEED, angle*SPEED);
Thanks.
It depends a little bit if it's 2D or 3D but the idea is basically the same.
I would start by making a Vector class which has to variables, x and y. I would then add a few method for adding and subtracting Vectors. What you would have to do then would be to subtract from the touchPosition Vector the firingPosition Vector which would give you the direction Vector towards which you have to shoot.
If you need more help with this just comment.

Flick or Toss ball

I'm currenty creating a project that allow user to drag the ball and flick the ball towards
the goal (football penalty kick/basketball shooting game).I've been searching on how
to flick the ball that will create a trajectory or even thrown into direction which
intended by the user.
I modified the project uploaded in below path but there is no success.I was able to stop the constant moving of the robot, which dragging of the image in any parts of the screen was left but I was not able to create another changes.
http://obviam.net/index.php/moving-images-on-the-screen-with-androi/
I'm needing an example similar to kicking the ball or flicking the ball or tossing the paper game.
Thank you.

Android OpenGL touch direction on a cube

I have a cube in my OpenGL view which I can rotate when I touch outside of the cube. Now I can detect which side of the cube I touch and now I'm trying to find out towards what side the touch movement is going. So if I touch the top side, the movement can go towards LEFT, RIGHT, FRONT or BACK side of the cube. The cube's orientation can be anything when doing this.
so after figuring that out I'd make it rotate around the correct axis.
I just need an idea of how to implement this.
EDIT:
Here's a crude example of what I'm trying to do. Sorry, I'm bad at explaining.
the green thing is a finger touching the red side. The arrow shows the direction the finger is moving. Since it's moving towards the blue side (2), it should return 2. If it moved towards the green side (1), it would return 1 and so on.
Here is an approach:
When you swipe and lift your finger up, you get two 2D points in screen space: ptBegin and ptEnd. Convert these to 3D (you will need to do an equivalent of gluUnproject to get the 3D coords) and you will get the 3D coordinates ptBegin3D and ptEnd3D in the cube's coordinate system.
Calculate the vector D = ptEnd3D - ptBegin3D.
Now, if you do a dot product of above with the cube face normals (0, 0, 1), (1, 0, 0), etc., you will know from the value which cube face you are moving towards.

Categories

Resources