How to add rotation to player collider within floppy bird type gameplay?
As part of learning unity I made a simple game in which the player flips a bottle cap that rotates and travels across the scene with random bottles as obstacles to avoid.
Here is a gif of gameplay: https://gfycat.com/EveryRegalGecko
The problem I encountered is the main player game object's Capsule Collider that matches the sprite image (bottle cap dimensions) can't be used with my code without destroying the game mechanics of flipping it straight up. Instead when the player taps the screen the capsule will go in the direction it's facing (constantly changing with the rotation so hard to play).
I found a solution to make it work by creating a sphere as the collider and placing it so it generally covers most of the player sprite (bottle cap), and not apply rotation (only to the sprite). This allows for the player to be flipped up regardless of orientation but it's not accurate as some extra space on top and bottom is added that will result in a collision that's not realistic. I had to redo the colliders on the obstacles (bottles) to make it appear realistic.
Here is a screenshot of the two colliders, the sphere is the one I resort to in order for it to work, the rectangular collider is the one I would like to use. http://imgur.com/UxsJ9Jg
Here is the main code I use to make the player object "flip". It goes straight up (if I'm using a sphere as collider) and it will go relative to up direction of object if I use the rectangular collider. I also have some screenshots of the inspector I'm using here. http://imgur.com/a/gcH2a
public Transform shotSpawn;
private float nextFire;
private bool gameOver;
private bool fuelFire;
void Update()
{
{
transform.Rotate(new Vector3(rotationX, rotationY, rotationZ) * Time.deltaTime);
}
if (fuelFire == true && Time.time * 1.0f > nextFire)
{
GetComponent<Rigidbody>().velocity = transform.up * speed;
nextFire = Time.time + fireRate;
Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
fuelFire = false;
}
}
Thanks for any advice or direction to make the game mechanics better.
Your answer
Follow this Question
Related Questions
How to rotate an object relative to another different object's axies? 0 Answers
Make GameObject rotate around another around random axis but with fixed distance 0 Answers
How would I add rotation limits to this? 1 Answer
How can I flip a player over the Horizontal and Vertical axis? 0 Answers
Get object's rotation around axis defined by vector 2 Answers