For school I have to make a game for my iPod touch, I chose to do an asteroids game. I have just started with cocos2d but have read the wenderlich blog. I wanted to use chipmunk in my game, i want realisitc motion of the ship. Is there a tutorial on creating the asteroids motion?
Thanks.
Simple Way
Learn a bit about vectors. http://chortle.ccsu.edu/VectorLessons/vectorIndex.html
Movement is usually calculated by adding a vector scaled by a time delta to the current position. (Math talk makes simple things so complicated).
Basically: new_Pos = old_Pos + mov_Vec * time_delta
So by changing the mov_Vec you can increase/decrease speed.
You can also do it on x,y new_x = old_x + mov_x * time_delta
Using Physics Library
If you are using a physics library, you can apply force to an object to move it. You can also set the angular velocity if you want it to rotate.
If you were using Box2d you would do something like this:
body->ApplyImpulse( b2Vec2(1,1), body->GetWorldCenter() );
There's a difference between applying force and an impulse in box2d
Some sites to check out
http://gpwiki.org/
http://www.gamedev.net/
http://www.devmaster.net/
http://box2d.org/
Airship motion in space is pretty easy to simulate... I don't think you need a library for that.
The ship has a velocity vector: depending on your input method, you shall only add a vector to change the speed (or reduce modulo when braking, if braking is allowed).
Just limit the max modulo of the ship, and you're done.
Sorry if this isn't really a reply to your answer.
HIH
Related
I am building an IOS game in Cocos2d - Chipmunk - Spritebuilder. I need to make a characters orbit around around a point, and I was having quite some difficulty in implementing orbits with real physics.
So far, I have tried two methods, one is creating a distance joint from the player to the planet, and then applying a 90 degree force on the player where an angle is created between the end of the distance joint and an imaginary line drawn at a 90 angle to it. He moves around crazily and this method is not working for me.
I then tried calculating 180 points on the circumference at a radius from the planet (which is the bounds of detecting and implementing its effects on the player) - and then in a scheduled update method [character.physicsbody applyForce:nextCircumferencePoint]; This does not work, as he does not follow the path exactly and is quite far from it. I am thinking that I need to also apply a gravitational force towards the planet which would cause him to circle it. Though I don't know how to calculate that force, apply it, or if it would even help.
A third method which would never work, but was used for testing was to set his position to the next circumference point. He does orbit, but any collision won't work (such as if a piece of space junk goes in his way.) He will simply be positioned right over any other object. This world great if you don't need collisions, are writing your own physics engine. This is not a polished way of doing things, so will avoid it.
Please correct anything I have already done and tell me how it would work, or shed light on other options and how to implement them.
Check out my answer here. It's for box2d, but you can do it with Chipmunk. If bodyA position will change, orbit will be same. You just need to change speed of body movement for your needs, just increase smoothness and slow down your update method.
I'm actually looking after technical solutions to program a study assistant for the game of Go. What annoy me in existing programs is tha fact that the real life perspective of the player's eye looking at a Goban isn't respected.
GlGo exists, but while the number of stones increases, the rendering dramatically slows down due to the number of stones, disabling to possibility to add frames with statistical information on to of the Goban, that would break the real-timeness of the application.
So, my Question is:
Would it be possible to realize an interpolation of a simple 2D Goban to make the board & stones looks-like 3D, but without 3D rendering engine? The board movement would only be along one axis.
Certainly: All you have to do is doing the 3D to 2D transformation. Then simply draw your stones using sprites. If you scale them, you only need a white and a black one.
As for transformation, a simple one could be something like this:
x = left_border + board_x * gridwidth;
y = top_border + board_y * gridwidth / 2;
If you want perspective etc. it's getting a bit more complicated, but in general it shouldn't slow you down significantly unless you're doing something wrong.
I have a simple question about a game I am making using box2D and cocos2D. I started using the physics engine yesterday so I am rather inexperienced with its usage and capabilities. My game involves rolling a ball around the screen using the accelerometer. I want to add holes to the ground that if the ball rolls into, it will then require a greater acceleration via the accelerometer to escape the hole pocket. I've toyed with friction, linear damping, modifying the accelerometer's gravity vector, and tried adding attractive forces but I haven't had too much success and some of it doesn't really simulate well what I want happening. Basically I just want to create some sensors and give them the properties of a small pocket a ball can fall in to. Any tips and advice is much appreciated. Thanks
I suggest you to use Level Helper . Its an awesome tool to create physic based games.
You can find it here
You could take the y position of the ball every frame and if it is below a certain threshold, then it is in a hole. Based off on this, if the ball is in a hole, reduce the sensitivity. When the ball exits the hole, put the sensitivity back to normal.
As for creating the holes, use Vertex Helper to create bodies that will correspond to your sprites.
If you need more explanation, feel free to ask.
Elaborated:
Now, basically in the picture, I am depicting what I tried to describe earlier. All you really have to do is to change the tilt sensitivity if the player's Y position is below a certain point. I just used 50 as an example.
Some pseudocode:
- (void)update:(ccTime)dt
{
if (player.position.y >= 50) { //If the player's y position is above or equal to 50
if (sensitivity != normalSensitivity) { //We don't need to set it every frame, so lets check
sensitivity = normalSensitivity;
}
}
if (player.position.y < 50) { //If player's position is below our threshold of 50
if (sensitivity != limitedSensitivity) { //Check so we don't set the sensitivity every frame
sensitivity = limitedSensitivity;
}
}
}
Now, as far as Vertex Helper is concerned, it is an open source tool (I believe) that helps you define vertices for custom shapes that can then be copied and pasted directly into your box2d or chipmunk cocos2d project. It can be fond here.
I suggest googling around for tutorials on how this is used. It is very simple, but you may need a quick reference to get you started.
Finally, something to remember, is that box2d can only work with convex shapes, not concave.
A convex shape is a shape where in is impossible to draw a line from any vertex to another without passing through the shape itself. Basically something that has no indentations in it.
I hope this helped. I'm not sure I can elaborate anymore than I have, but if you have more specific questions, feel free to ask.
I'm new to using Box2d and really can't find a consistent answer to my question so please excuse me.
I'm writing a game for the iPhone -- who isn't these days -- and I'm using Cocos2d and Box2D. I have objects that move around in the game and I would like to give them a more of a curved path. From my studies I know that I should use body of type b2_kinematicBody which allows me to change the linear velocity every tick and keeps them from colliding with my other flying bodies. I do understand that if I know my current position (x,y) and my next position in the step (x1,y1) I would be able to compute the vector for velocity. Does anybody have a good way to give an object a defined curved path? I'm thinking it has to be some kind of parametric equation.
Take a look at bezier curves. After curve defenition you can compute the derivative (it's easy for bezier) and use it as a velocity for your body
OH whats the game called? sounds like a good one. have you looked into maybe just doing that in version 2.0
I'm just starting with cocos2d + box2d.
I would love to create a simple 2d ship game where you look from top(from the sky) down at the sea with the ships.
Could someone give me a very very basic example, how to apply wind to my world? Do I have to applyForce to each ship body?
And what about the gravity? Since it goes straight down, should I set it to 0? gravity.Set(0.0f, 0.0f)? It actually would pull down the ship..
Should I somehow deal with the water? e.g with density of it?
you would probably have to detect where the ships are and then apply force on them somehow.
and yes set gravity to 0.
and water wouldn't have to be an object at all. just like a background image.
If you are looking from the top and want to apply wind force to all your ships you can use gravity vector. In this case wind force will be applied to your objects automatically.
If there are other dynamic objects on the scene then it's a good idea to keep the list (std::list or NSMutableArray) of pointers to all your ships. Notice, that by default box2D is clearing all the forces each simulation step. You can disable this property or apply forces manually each simulation step