In my cocos2d game I would like to use tilt controls. The game is in landscape left only, for keeping it simple.
Now, if the user tilt device backwards, eg, tilt the screen upwards, the player sprite is moving up(+y). If the tilt is in the other direction(turning screen downwards) the sprite moves down. -(y)
The problem is that the device is pretty much in downward tilt from start and the player sprite moves down quickly. To get it moving up I have to tilt the device so far that I canĀ“t see the screen.
So is there anyway to make the tilt less/more sensitive based on what direction the said tilt is?
You need to set a filtering factor for this. Take a look at the tutorial at http://www.raywenderlich.com/3611/how-to-make-a-space-shooter-iphone-game which goes through how to use the accelerometer for this type of movement.
Related
I am wanting to move a sprite in the the direction it is facing. I got everything I need except the sprites current angle. It is rotating back and forth like a pendulum forever, but when the button that moves it is tapped it stops rotating and moves in the direction it is currently facing, or at least thats what I want it to do, but I don't know how to get the value for the current angle. Could someone help me out? =)
I writing a program in C++ using OpenGL/win32 of a ball that bounces when it's dropped from a height above either of the planes/platforms you see below.
I use plane sphere intersection and plane-sphere collision to make the ball fall/bounce accordingly (not a bounding box).
I'm now hoping to make the ball roll over the edge of the plane like it would in reality if more than half the ball is over the edge.
I was wondering what other forces I would need to simulate and how that can be implemented? I currently only simulate gravity based on the y-axis and a velocity for the return of the bounce.
As things stand, the ball can go right to the edge of the plane and as it slowly moves away, it will drop a little the further right it goes, but still remains on the platform until there's no-longer a collision. (I hope that makes sense). I've screen shot these images to try to show it:
On the edge, before it should fall:
Still on edge, but should be falling (although dropped slightly):
Drops only after the far left of the sphere is no-longer touching the plane:
The concept you have to introduce is the Torque, moment or moment of force.
which in computing is often reference as torque.
I have a single dynamic body(Bike) with three circular fixtures: frontTyre, backTyre and body. When I apply force on the bike, it moves and jumps off the click. The bike doesn't have fix rotation, so it rotates and doesn't land properly on the terrain. I have two buttons for rotating bike: one for right rotation and other for left rotation. I tried giving torque to the bike when it is air, but not able to control the rotation. What is the best approach for such a controlled rotation. Any help would be greatly appreciated.
check this out ,
you can fully control the rotation using this
http://www.iforce2d.net/b2dtut/rotate-to-angle
I am trying to learn box2d in cocos2d. I have searched for online tutorials and ray Wenderlich's seem to be the best ones!I am learning in a slow but steady pace! I am currently developing an app in which I will include a ball in the screen, and every time I touch/tap this ball, it is going to move like someone is flicking a soccer ball. I have coded the part for the upward movement(y axis) of the ball, when touching/tapping it. The problem that I encounter is that I can not find a way to give the ball the appropriate angle in order to rotate and move on the x axis. Let me give you an example. Imagine you are flicking a soccer ball, you kick the ball upwards but also there is a spinning force on the ball. I am trying to develop the spinning and moving across the x axis part. I would like to touch the ball, in its lower right "corner" for example and spin and move in a realistic way. Touching it in the lower right "corner" while the ball is in the air, means that the ball will move and spin to the left side of the screen. I hope I clarified the situation! I would be grateful if someone could help me to understand that kind of movement! If you still haven't understand the concept of my game, search for "parksoccer" and you will understand what I am trying to develop.
I did this yesterday only. In this case what you can do is when you touch or tap a screen , you take that point in ccTouchesBegan and then find the position of the ball by GetPostion() method on body. Than you have to calculate the angle between these two points and find in which direction ball will go from these two points. now you have angle and direction in which ball will go so apply linearForce on that by ApplyLinearForce(b2vec2 forceangle, body->GetPosition()). Thats it.
Enjoy.
I've been using OpenGL with SFML 1.6 for some time now, and it has been a blast! With one exception: I can't seem to implement a camera class correctly. You see, I am trying to create a C++ class called "Camera". Here are my functions:
Camera::Strafe(float fSpeed)
checks whether the WASD keys are pressed, and if so, move the camera at "fSpeed" in their respective directions.
Camera::MouseMove(int currentX, int currentY)
should provide a first-person mouse look, taking in the current mouse coordinates and rotating the camera accordingly. My Strafe() implementation works fine, but I can't seem to get MouseMove() right.
I already know from reading other resources on OpenGL mouse look implementations that I must center the mouse after every frame, and I have that part down. But that's about it. I can't seem to get how to actually rotate the camera on the spot from the mouse coordinates. Probably need to use some trig, I bet.
I've done something similar to this (it was a 3rd person camera). If I remember what I did correctly, I took the change in mouse position and used that to calculate two angles (I did that with some trig, I believe). One angle gave me horizontal rotation, the other gave me vertical rotation. Pitch, Yaw and Roll specifically, although I can't remember which refers to which direction. There is also one you have to do before the other, or else things will rotate funny. I'm pretty sure it was pitch first, then yaw or roll.
Hopefully it should be obvious what the change in mouse position did. It allowed mouse senesitivity. If I moved the mouse fast, I would have a larger change, and so I would rotate "faster."
EDIT: Ok, I looked at my code and it's a very simple calculation.
This was done with C#, so bear with me for syntax:
_angles.X += MathHelper.ToDegrees(changeInX / 100);
_angles.Y += MathHelper.ToDegrees(changeInY / 100);
my angles were stored in a 2 dimensional vector (since I only rotated on two axes). You'll see I took my changeInX and changeInY values and simply divided them by 100 to get some arbitrary radian value, then converted that number to degrees. Adjust the 100 for sensitivity. Keep in mind, no solid-math was done here to figure this out. I just did some trial-and-error until I got something that worked well.