Problems, Objects colliding in the wrong way Unity3d

Asked

Viewed 667 times

1

I have a problem that I haven’t been able to find the solution to:

I’m trying to finish a project with Unity, a simple 2D racing game, where the camera is static from above and the objects descend by gravity. This functionality nearly complete, the scripts are working properly, the car and the Power Up moving as they should, but the moment the money goes through the car is the problem, rather than crashing and disappearing adding to the score, the car is being dragged with it.

I’m sending two screenshots of the Inspector of the car and the money.

inserir a descrição da imagem aqui

Link to the video lesson of this project that I am basing myself on.

At the end of this class, the author refers to marking Is Kinematic to solve the collision of the objects "car", "money".

  • 1

    First thing your money object should be Rigger because when you hit the car it will not reduce the speed of it If possible send a print of the code to see if the problem is there

  • Gentlemen, thank you for your answers. But I still haven’t been able to solve this small detail. I’ll send you a link to a video lesson where I’m following. Almost at the end Nils says that to solve this collision is only to mark the option " is Kinematic " but with me this does not work https://youtu.be/wFGwk7edyYA

  • I could post a comment to Nils with the link of your question here, I believe he has not seen.

3 answers

1

Good afternoon Jhonny Summer

I advise you to use Ontriggerenter2d, if the money does not affect anything in the direction of the car when colliding, When it is used the Trigger it does not assign the effects of physics as two bodies colliding =D, I hope it helps, make the comparison within that -> http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerEnter2D.html

Don’t forget, the object that is linked to script that has the Ontriggerenter2d method must be with the Marked "On Trigger" Researcher.

Any doubt we’re there.

0

I can’t visualize the images Jhonny but I’ll take a wild guess considering your whole system is really gravity-based.

In this case you must have a Rigidbody2d on all your objects. The attribute "mass" of your object of money must be very large in order to cause influence on the cart when it collides, already in the Powerup it must be much lower and therefore not enough to cause a displacement before the object is destroyed.

Some things you can revise to try to fix:

1: Compare the values of the rigidbody attributes (mainly: "Mass", "Gravity Scale" and "Is Kinematic" ) and try to make your money object equal to Powerup’s.

2: Compare the attributes of the colliders (mainly: "Is Trigger") and leave the cash attributes equal to those of the Powerup...

3: Check how/when the Powerup is destroyed in his behavior script and whether the money has a call to be destroyed as well (It may be that as it is not being destroyed by crashing it falls on the trolley and stays there adding to the mass and gravity influence that the car suffers causing the unwanted effect).

0

Try to integrate not only Rigidbody2d but deactivate the object to be collided and if you have any transaction with Sprite activates the Animator and disables the object or destroys it (in case the destruction is more advised to consume less memory).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.