Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 fdsdfg · Jul 18, 2014 at 04:28 PM · physicsrigidbody3dmousecontrol

How should I control a 'rake' that pushes objects around a table?

I won't get into too many details about my game, but I have a flat table that has a bunch of objects on it. Using the mouse, the player needs to be able to push these objects around, push them off the table, push them into a hole in the table, etc.

Right now I have a 'rake' rigidbody with 'kinematic' enabled, with a box collider - and I'm using the 'rigidbody.MovePosition' method to move it in line with the mouse movements. There are three major problems:

1) Even though the hitbox touches the surface of the table (and even extends below it a bit), sometimes the objects get 'stuck' and the rake passes right over them with barely a nudge, or flipping the object over.

2) Moving the rake quickly will very often pass right through objects.

3) Sometimes a small twitch will send the objects flying, even though the rake isn't moving very far.

I've tried a few different ways to let these objects interact, but I'm not familiar enough with Unity to know what options I have.

I want this to feel like you're really pushing objects - when you pull the rake through a pile, it should just pull them all with the rake and not leave any behind.

Thanks for any advice.

Comment
Add comment · Show 6
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 Addyarb · Jul 18, 2014 at 07:55 PM 0
Share

Are the objects rigidbodies too? Try changing your rake's collision on the rigidbody to "Continuous Dynamic," as fast or unexpected jerks of the rake will sometimes cause unexpected behavior.

Try adding mass to your objects, and make them use gravity if you are not already.

I would try to make the collision box match exactly flush with the table, ins$$anonymous$$d of trying to extend under it. Does your table have a collider too? $$anonymous$$oving a collider through another collider like that (Rake through table in this case) can sometimes confuse objects with other collision detection into thinking the table itself is moving.

Let me know if any of this helps!

avatar image fdsdfg · Jul 18, 2014 at 08:32 PM 0
Share

Hi.

Yes, the objects are rigidbodies that obey gravity.

I will try giving them more mass, I will try making the collider exactly flush with the table. Yes, the table has a box collider, but not a rigidbody. Since the Rake is kinematic, they don't interact at all, but I can see how it would mess with detection.

avatar image Addyarb · Jul 18, 2014 at 09:01 PM 0
Share

Okay great, if you'd like to post a picture of the issue perhaps I can offer different solutions. Namely, pushing the objects manually with vector3 at the speed and direction of the rake using an OnTriggerEnter function. That would give you very predictable results, unlike the physics engine solution you're currently using.

avatar image fdsdfg · Jul 18, 2014 at 10:15 PM 0
Share

I made the first change you suggested to the box collider, and it made the problem worse =(

I couldn't get a video to record properly, but I took some screenshots:

http://imgur.com/a/Dc443

Images 1 and 2 are the result of dragging the rake through the pile at a consistent speed over a period of about 1 second. I didn't mention it, but in my project settings I turned '$$anonymous$$in penetration for penalty' to .0001 - to try to prevent the objects 'sinking' into the floor.

Images 3 and 4 are an unrelated glitch that is also happening pretty often. There are two box colliders in the table that are touching, and the cards have a thickness of .02 (the rake height is .4 for comparison). I could just throw more box colliders to overlap any cracks in the object, but that feels like the wrong way to fix this.

I thought about your solution to add force, but isn't that what the physics engine basically does anyway? I feel like I'm trying to reinvent the wheel if I go down that path.

edit:

I played around with this a bit more. Even when I make things much thicker, they still sometimes duck under the rake. Looking closely, I can see the rake is pushing them forward a bit, but then they get pushed downward into the table, and resurface behind the rake - like ice floating in water. I'm guessing all my problems revolve around the fact that everything sinks into the table too much.

avatar image Addyarb · Jul 18, 2014 at 11:05 PM 0
Share

I see, okay try this: Somewhere in your script, lock the Y axis of your chips by setting it's Y value manually. This should inevitably prevent any sinking.

function LateUpdate() { ChipsOrDollars.transform.position.y = 2.0;
}

EDIT: You don't/won't have to use the translate.position scripts in conjunction with this fix, you can just put a simple script locking the Y axis of your chip/group of chips and it should stop the sinking. Just make sure it's LateUpdate or you may run into some issues.

Show more comments

2 Replies

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

Answer by fdsdfg · Jul 19, 2014 at 04:02 PM

I messed around with this a lot, and found out it was because when I move the 'rake' rigidbody, the objects don't know whether to go forward (pushed across the table, what I'd expect to happen), or down (sink into the table, bad).

I figure this is because instead of the rake having a force moving in one direction, the 'moveposition' just sort of places it on top of the object - and the object will choose the shortest path out of the collider - which can often be down.

I fixed this by having the collider extend very far down into the table - so there's no way the shortest path would be anything other than parallel to the table surface.

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 Addyarb · Jul 19, 2014 at 04:04 PM 0
Share

Cool! I'm very glad you got it working as expected, and I'll remember this fix when I inevitably come across a similar situation.

avatar image
0

Answer by Addyarb · Jul 18, 2014 at 10:52 PM

 using UnityEngine;
 using System.Collections;
 //Attach this script to your chip objects, or possibly even a group of chips with their own colliders.
 public class PutObjectsInHole : MonoBehaviour {
     public GameObject Rake; //Name your rake "Rake"
     public GameObject Hole; //Name the hole in the center of the table "Hole"
     public float RakeSpeed = 5;
     public float TableHeight = 10.111f; //Set the exact (to the hundredths or better) position of your table's collider's top surface.
     public Transform ChipOrDollar;//Adjust this to make the raking of objects more realistic by matching it's speed.
     // Use this for initialization
     void Start () {
         Rake = GameObject.Find ("Rake");
         Hole = GameObject.Find ("Hole");
         ChipOrDollar = transform;
     }
     
     // Update is called once per frame
     void LateUpdate () {
         ChipOrDollar.transform.position.y = TableHeight;
     }
     void OnTriggerEnter(Collider col){
         if (col.gameObject.tag == "RakeTag") {
 
             ChipOrDollar.position = Vector3.MoveTowards(transform.position, Hole.transform.position, RakeSpeed*Time.deltaTime);
                 }
 
 
         }
     void OnTriggerExit(Collider col){
         if (col.gameObject.tag == "RakeTag") {
             GameObject.Destroy(ChipOrDollar);
             Debug.Log ("Here is where you would add the chips to a player")
                 //if(ChipOrDollar.tag = red){
 
                 //chipScript.score += 10;
                 //}
                 }
 }

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 fdsdfg · Jul 19, 2014 at 12:45 AM 0
Share

Thanks, but it is really important that the objects are pushed around in response to physics, and can go in any direction - they can't just be 'scooted' toward the goal. Even if I had them move in the direction the rake is moving, it's still very awkward compared to physics force being applied.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to make camera position relative to a specific target. 1 Answer

Shake Effect 0 Answers

Inconsistency in Rigidbody.MovePosition 0 Answers

F-Zero Game - Collisions/Physics. 1 Answer

Does setting the rotation of an object override the physics engine? 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