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
0
Question by TimFraser · May 24, 2020 at 02:38 AM · physicsdriving

Forklift Pallet Slides off Forks

Hey,

I am making a small game where you control a forklift and compete to pick up pallets and bring them back to your dock. I am having some trouble with the pallet swinging/sliding off the front of the tines because of the momentum of turning the forklift at a high speed. The physics seems to be working fine but I would like to fix the pallet more to the tines so it isn't as easy to drop the pallet. I have tried increasing the drag and angular drag but it ends up slowing the forklift down majorly. I have looked at swapping the pallet to "is Kinematic" when the pallet is picked up but it causes more problems along with slowing the forklift down. I have about 9 child empties with box colliders to make up the shape as non-convex mesh colliders don't work with non Kinematic objects. I don't know if that is causing problems. I have the pallet parenting to the tines when it is picked up but it still slips off the front.

The optimal final output is the pallet sticks to the tines no matter how the forklift drives around but if the forklift runs into a wall with the pallet lifted above the wall, the pallet can slip off into the 'goal'. Sorry if that is too much to ask haha, I am quite new to programming and just kind of stumbling my way through. Thank you.

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 toficofi · May 24, 2020 at 12:41 PM 0
Share

Have you tried increasing the friction on the palette?

avatar image TimFraser toficofi · May 26, 2020 at 09:16 AM 0
Share

Hey Joshius,

Thank you for your reply. Would I do this through a Physics $$anonymous$$aterial as enerology suggested or is there another way to adjust the friction?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by enerology · May 24, 2020 at 01:12 PM

For the first part, to prevent it from sliding off right, but sliding off when enough force is applied, static friction is the field you want to change.

Now that I know that you are parenting the object to the forklift, there is a better solution using the parent method. You can change the rigid body to kinematic when its parented and when the forklift hits the section you want it to drop into to. Detect the collision with the wall using a trigger on the front of the forklift and when this happens, turn the rigid body back to dynamic and add a force to propel the pallet off of the tines. (you can scale the force with forklift velocity to give a more realistic effect. Here is the first pseudocode for the forklift

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class ForkliftController : MonoBehaviour
 {
     public GameObject currentPallet;
     public float releaseForce = 10;
 
     public void releasePallet()
     {
         //Set parent transform reference to null
         currentPallet.transform.parent = null;
         Rigidbody rigidBody = currentPallet.GetComponent<Rigidbody>();
         //enable dynamic rigid body.
         rigidBody.isKinematic = false;
         //You might need to add or subtract from this angle if the pallet doesnt get pushed in the right direction
         float angle = gameObject.transform.eulerAngles.y;
         //Add a force to the pallet to send it of the tines
         //If you want, you can multiply release force with forklift velocity
         rigidBody.AddForce(new Vector3(Mathf.Sin(angle) * releaseForce,0, Mathf.Cos(angle) * releaseForce));
 
     }
 
     public void grabPallet(GameObject pallet_)
     {
         //Set Reference to pallet
         currentPallet = pallet_;
         //Disable dynamic rigid body
         pallet_.GetComponent<Rigidbody>().isKinematic = true;
         //Set its parent to the forklift
         pallet_.transform.parent = gameObject.transform;
     }
 
 
 }





Then you want to create a game object with a trigger on it and place it on the front of the forklift where it will collide with the wall. Then add this script and call the releasePallet() from it.

 using UnityEngine;
 using UnityEngine.Events;
 using UnityEngine.EventSystems;
 
 public class CollisionTriggerController : MonoBehaviour
 {
 
     public void OnCollisionEnter(Collision collision)
     {
         MyOwnEventTriggered();
     }
 
     //my event
     [System.Serializable]
     public class MyOwnEvent : UnityEvent { }
 
     [SerializeField]
     private MyOwnEvent myOwnEvent = new MyOwnEvent();
     public MyOwnEvent onMyOwnEvent { get { return myOwnEvent; } set { myOwnEvent = value; } }
 
     public void MyOwnEventTriggered()
     {
         onMyOwnEvent.Invoke();
     }
 }
 

Feel free to comment more if this does not work or you have some more questions! Good luck with the project.

Comment
Add comment · Show 3 · 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 TimFraser · May 26, 2020 at 09:14 AM 0
Share

Hey enerology,

Thank you for your reply, sorry I have been slow on $$anonymous$$e. I added a physics material to the pallet and it seemed to work about 50%. From what I can see it looks to have added friction but no matter how high I increased the value it still slips off. Something else happened where if the pallet is parented to the forks, then the pallet moves at twice the speed of the forklift but only while the tines are moving either up or down. It doesn't do this without the Physics material with all the other variables the same and I am not sure why the physics material would push the pallet in a direction.

Any additional help you could give me would be greatly appreciated.

avatar image enerology TimFraser · May 26, 2020 at 06:10 PM 0
Share

I changed my answer to reflect the new information. Good luck with the project!

avatar image TimFraser enerology · May 27, 2020 at 05:20 AM 0
Share

Wow dude! Thank you so much. It may take me a couples days to implement it but I will let you know how I go. Thanks again!

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

207 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Implementing Simple Cart Physics? 1 Answer

2D 360 degress platformer example needed 0 Answers

Character Rides In Vehicle 1 Answer

How is wheelCollider RPM calculated exactly? 1 Answer

limiting player rotation 0 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