Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Trickman · Jul 27, 2016 at 07:12 PM · collisionphysicsvelocityaccelerationcompound collider

Character accelerates while running towards walls. "Sonic effect"

Hi everyone,

Imagine if your game was 2.5D, and you couldn't rely on force physics for everything, since your models are 2D sprites encased in invisible spheres and cubes. Some of the game's physics must be coded by yourself or it looks unrealistic (the sprites are flat, and any tilting or movement on the invisible cubes or spheres that contain them creates a weird effect).

Now imagine if you're playing a car/racing game. You hit a lamp post on the track and keep accelerating, pushing towards it. The lamp post isn't destructible, so your car doesn't move. However, acceleration in the movement axis is still taken into account, and as soon as you slide off from the lamp post, you get shot forward unrealistically at high speeds:

alt text

These two things create an impossible combination for me: I have to manually assign velocity to the character based off the Axis acceleration, so every time the character gets stuck in an obstacle, he can slide off and max speed for an unrealistic effect. I call this the "Sonic effect", because it works similar to when Sonic charges up his spin-dash and then gets shot forward.

To solve this, I've tried many things, but the only sensible solution is detecting which of the 4 sides of the object the character is colliding with, and annul all axis acceleration towards that place.

The problem is that I can't make 4 colliders for an item without them being treated as a compound collider, and detected as if they were only 1 collider

... Or can I?

Does anybody know a solution to this? I can't believe I'm the first with this problem, but I've been looking for questions like this one and I can't find any.

Thanks in advance!

car-and-obstacle.png (15.2 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Sspyrshlsx · Jul 10, 2020 at 08:36 AM

Well, probably I'm a bit too late -like 4 years- but I seriously couldn't find any answers for a similar issue. And this is a core thing for acceleration. I don't know if you already found an answer or not, but I'm writing to let other people know, since this is one of the first posts I encounter when searching the topic.


Anyway, so in my case I had a simple platformer controller that can accelerate. It moved with rigidbody.velocity and it had acceleration and deceleration values. There were 2 issues. 1)Whenever I hit a wall, the player keeps decelerating. 2)When I keep pressing the movement key and jump on top of the wall, I get launched with max acceleration.


The way I handled the first issue was, when my character hits a wall, the rigidbody.velocity's x axis equalled zero. Which means, if I checked if rb.velocity.x == 0, I could reset my player's deceleration value so whenever I stop, I don't decelerate anymore, which totally makes sense in any situation.


I also had a moveSpeed variable, which slowly equalled to a maxSpeed value. I achieved this with Mathf.SmoothDamp, smoothing the value over the acceleration and deceleration values depending on which key has been pressed. So for the second issue, I made something quite similar. I just set the moveSpeed value (NOT MAX SPEED) to 0 when rb.velocity.x was 0. Which again made sense because when not moving, the player can surely have no speed.


As far as I understood from what you have written above, the car gets a full stop when hitting a lamp post. So setting moveSpeed to 0 should hopefully help out. Regards.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sspyrshlsx · Oct 27, 2020 at 09:47 PM 0
Share

Edit: This post just got answered and it might be a more clever solution for anyone needing help.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

I want collision boxes to be precise without overlapping each other 1 Answer

How to transfer bat's transnational and angular velocity to ball to simulate realistic ball movement. 0 Answers

Ignore collision at high velocity. 1 Answer

arrows in unity 3d? 0 Answers

AddForce moving object in wrong direction 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges