Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
0
Question by Mattyizz · Feb 14, 2014 at 03:19 PM · collisioncollision detectionlerp

Handling collision with fast Lerp

I have a game, where the player is an object that is Lerped to the position underneath the mouse. You must dodge oncoming objects.

Problem is, when you move your mouse outside the screen in the top, and then back inside in the bottom, the player will almost instantly Lerp to the bottom, completely ignoring collisions with any objects inbetween the top point where you exited, and the bottom point where you entered.

Do I have any options here, or do I have to hard-code/hack some stupid raycast check before Lerping?

EDIT: I should probably mention, that collision is handled with a rigidbody on my object, as well as on all obstacles. Obstacles are triggers, player is not.

Comment
Add comment · Show 2
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 whydoidoit · Feb 14, 2014 at 03:19 PM 1
Share

How are you moving the object? You need to do it in physics with $$anonymous$$ovePosition.

avatar image Mattyizz · Feb 14, 2014 at 05:02 PM 0
Share
 void $$anonymous$$oveTowards (Vector3 pos) {
         Vector3 newPos = new Vector3(pos.x, transform.position.y, pos.z);
         transform.position = Vector3.Lerp(transform.position, newPos, moveSpeed * Time.deltaTime);
     }


I am moving the object like this, with the input Vector3 pos being the raycast-located mouse position in world space.

I want the movement to be fluid ie. lerping, so the object is slightly lagging behind the mouse. Does $$anonymous$$ovePosition accomplish this?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Mattyizz · Feb 14, 2014 at 05:08 PM

Actually, this fixed the problem:

 void MoveTowards (Vector3 pos) {
         Vector3 newPos = new Vector3(pos.x, transform.position.y, pos.z);
         rigidbody.position = Vector3.Lerp(transform.position, newPos, moveSpeed * Time.deltaTime);
     }

Calling the function on the position of the rigidbody instead of the transform.

You're a champ, thanks mate.

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 whydoidoit · Feb 14, 2014 at 05:21 PM 0
Share

Hopefully that will work on all platforms, you used to have to use $$anonymous$$ovePosition on the rigidbody to ensure that the physics properly interacted, but it looks like just moving the rigidbody will do it now...

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

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can I have a single rigidbody2d that acts as both collider and trigger? 1 Answer

Objects don't collide 1 Answer

How would I go about setting an exclusive collision, i.e. floor that only reacts to the player? 1 Answer

Is there a better way to check for a collision with a prefab than by name or tag? 2 Answers

Collision & 2D 2 Answers


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