Tuesday, April 16, 2024
HomeSample Page

Sample Page Title


I’m right here as we speak to determine how can I’ve an object to fall down after colliding to a different object. In my case, I’m remaking Flappy Bird and attempting to reapply a few of the physics in place from the unique to mine as a fun and studying undertaking.

Yesterday, I got here to right here and a pleasant consumer helped me out with my downside (put up about rotating an object on particular angle whereas falling). It did wonders and wished to reapply the identical idea once more with the strategies used beforehand. Obviously, not the very same ones, however seize and take a look at out what works one of the best.

Now, that is what I’ve at this second and what I’m attempting to duplicate

(Mine. I’m doing body by body to level out)

enter image description here

(Original idea)

enter image description here

As you noticed, what I’m attempting to duplicate is the falling fowl from my present peak to 0 y-axis in fixed velocity (key phrase “velocity”). Currently what I’ve, is that I Clamp my present y-pos proper earlier than I collide and go to 0 (min: 0.0f, max: 0.001f). Which, in my view, it’s a short-term answer I received, however not appropriate for the precise job. I’ve learn extra into Lerp and SmoothStep, however I believe it is not going to be fixed velocity for what I’m attaining. So, as an alternative, I’m placing a watch into TransferToward() technique from my Bird vector to the ground. TransferToward() strikes your object a to maneuver in direction of to a different object b. In my case, it’s fowl to ground. I attempted to make use of it, nevertheless it doesn’t do the trick I hoped to do it or not utilizing it nicely sufficient. (supply in how I received into this level)

For now, let’s stick from what I’ve at the moment from the GIF instance I’ve supplied and share the code

personal bool gameOver = false;
personal Vector3 velocity;
personal void OnCollisionEnter(Collision collision)
{
    if (collision.gameObject.CompareTag("Grass_floor") || collision.gameObject.CompareTag("Pipe"))
    {
        HitAndDie();
        gameover = true;
    }
}

personal void HitAndDie()
{
    // velocity = Vector3.down;
   // velocity.y +=  my_gravity * Time.deltaTime; //I would like my Time.deltaTime() in right here, however not fairly certain if I'm utilizing it appropriately.
  float fallPosition = Mathf.Clamp(rework.place.y, 0.0f, 0.001f);
  rework.localPosition = new Vector3(rework.place.x, fallPosition, rework.place.z); //Here I'm simply mainly wish to give a brand new place to my object from the given clamp.
}

With this code, mainly my object fowl collides to a one other object and it outcomes to go to the ground because of the Clamping. Now, as soon as the fowl hits, the gameover switches to true and subsequently, the gameloop Update() is completed. I really feel like earlier than triggering my gameover to true, I must make the fowl to fall first to the ground and let gameover flip to true.

To get it down as a falling object earlier than the gameover flip true is what I’m attempting to attain right here. So that’s the reason I used to be wanting into TransferTowards() technique, which is what I’m picturing to offer me outcomes.

If you’ve got questions or one thing to level out, let me know so I can make clear and doubtlessly edit the put up a bit extra.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments