How to fix a car collision with an obstacle?

Not favoritedFavorited Favorited 0 favourites
  • 5 posts
From the Asset Store
Particles support animations, collisions, effects and etc.
  • The main goal was to make the car lose 1 hp when it hits an obstacle, but upon collision, it continues to remove more than 1 hp.

    I tried a few ideas, but I encountered some weird behavior.

    How can I fix the car collision with the obstacle when using car behavior?

    https://www.dropbox.com/scl/fi/n8jryp3izjfx4wdib1trn/Car-Hit-Obstacle.c3p?rlkey=6nu3gwbqn1so7knscrhn06121&st=u934dmwt&dl=0

    Try to test movement in reverse. Why it's pushing car back if car speed on reverse is negative? Bug?

  • Hello. Do you want to simulate damage so that the power of the car decreases when it collides with an obstacle?

    Then you need to reduce the current and maximum speed of the car and return it after receiving a repair booster.

    And it drives backward when it collides with an obstacle behind it because you programmed it that way; it's not a bug. I showed you how to fix it.

  • Hello, Igor! How are you? In my game there is no damage that effects on car stats, but idea is good. I want to reduce only 1 HP each time the car hits a wall. The idea was to push the car in the opposite direction of the hit to avoid multiple HP removal.(You can see it in yearly versions) When the car moves in reverse, the (car.car.speed) shows a negative number, right? There's a text display (Text 2) on the UI. I have a condition: if (car.car.speed) is greater than 0, then push. This means that if the car is moving in reverse, it should not be pushed, right?

    So, what’s the problem? Now, if the car moves backward and hits the obstacle, it's not pushing against the obstacle; it moves toward the obstacle. I reduced the speed and moved the obstacles behind the car to make it more visually obvious. I hope I was able to explain this clearly with my English

    How to determinate car hit was front or rear? I used car speed for that. If car speed is positive then on hit it's front. If car speed is negative then it's a front. Any better ways?

    updated "code"

    https://www.dropbox.com/scl/fi/9fdkeqr6nnagfgzapetr9/Car-Hit-Obstacle-2.c3p?rlkey=ms0heiqj9hpxtoj1c4vuvjovl&st=t6sqfiya&dl=0

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • ...

    How to determinate car hit was front or rear? I used car speed for that. If car speed is positive then on hit it's front. If car speed is negative then it's a front. Any better ways?

    updated "code"

    https://www.dropbox.com/scl/fi/9fdkeqr6nnagfgzapetr9/Car-Hit-Obstacle-2.c3p?rlkey=ms0heiqj9hpxtoj1c4vuvjovl&st=t6sqfiya&dl=0

    It is easy to determine whether the obstacle is in front or behind by knowing the angle between the car and the obstacle, as shown in the screenshot.

    Why don't you like this method?

  • Thank you very much! Your method works great, I'm a blind bad copy paster :D I lost - 180 in this formula: angle(Car.X, Car.Y, Obstacle.X, Obstacle.Y) - 180 and it obviously did't work! Then I started my own overcomplicated methods...

    Examples: manually calculating car speed Car.Car.VectorX * cos(Car.Angle) + Car.Car.VectorY * sin(Car.Angle),

    Setting X and Y position Self.X + cos(Self.Angle) * 20 and Self.Y + sin(Self.Angle) * 20

    By the way I discovered something interesting. Did you know that if car Friction is set to 1 then you can't move it or set new position?

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)