Tuesday, October 25, 2022
HomeGame Developmentunity - Altering falling conduct of my object after collision to go...

unity – Altering falling conduct of my object after collision to go regularly down and never immediately


I am right here at the moment to determine how can I’ve an object to fall down after colliding to a different object. In my case, I am remaking Flappy Fowl 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 needed to reapply the identical idea once more with the strategies used beforehand. Clearly, not the very same ones, however seize and check out what works the most effective.

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

(Mine. I am doing body by body to level out)

enter image description here

(Authentic idea)

enter image description here

As you noticed, what I am attempting to duplicate is the falling fowl from my present peak to 0 y-axis in fixed velocity (key phrase “velocity”). At present 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 non permanent answer I bought, however not appropriate for the precise activity. I’ve learn extra into Lerp and SmoothStep, however I feel it is not going to be fixed velocity for what I am reaching. So, as an alternative, I’m placing an eye fixed into MoveToward() technique from my Fowl vector to the ground. MoveToward() strikes your object a to maneuver in the direction of to a different object b. In my case, it’s fowl to flooring. I attempted to make use of it, nevertheless it doesn’t do the trick I hoped to do it or not utilizing it properly sufficient. (supply in how I bought into this level)

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

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

non-public void HitAndDie()
{
    // velocity = Vector3.down;
   // velocity.y +=  my_gravity * Time.deltaTime; //I want my Time.deltaTime() in right here, however not fairly certain if I am utilizing it accurately.
  float fallPosition = Mathf.Clamp(remodel.place.y, 0.0f, 0.001f);
  remodel.localPosition = new Vector3(remodel.place.x, fallPosition, remodel.place.z); //Right here I am simply mainly need 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 Replace() is finished. 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 am attempting to realize right here. So that’s the reason I used to be trying into MoveTowards() technique, which is what I am picturing to offer me outcomes.

You probably have 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

- Advertisment -
Google search engine

Most Popular

Recent Comments