Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Smooth force

Discussion in 'Editor & General Support' started by Samantha, Jul 3, 2006.

  1. Samantha

    Samantha

    Joined:
    Aug 31, 2005
    Posts:
    609
    I want to add a force to an object and have it look like I'm translating the object in an even manner.

    I'm trying to simulate a conveyer belt. Since I'm using Blender, I can't create an animated conveyer belt, so I'm trying to fake it. I've got a stretched out cube, with a scrolling texture on it. When an object falls onto the conveyer belt, I want to add forces to the object.

    Sounds simple, but I'm running into trouble with making the object look like it is moving with the conveyer belt. I can't use a constant force, because the object moves faster, and the different ForceModes for AddForce() are not doing the trick.

    I've tried pushing the object along with an invisible box collider, but that doesn't work either. The only thing I haven't tried yet is attaching a parent to the object when it hits the conveyer belt and translating the parent.

    Any ideas, thoughts, help? Thanks!
     
  2. mjjw

    mjjw

    Joined:
    Nov 12, 2005
    Posts:
    59
    If force isn't a problem while the object is on the conveyor belt you could just translate the object around at the speed of the conveyor belt.

    I have a similar problem in the game I'm making where certain objects just don't have the right feel when moving under proper physics so I have to take control of their movement at times instead of letting the physics engine work it's magic.

    I actually have to simulate certain collisions because I just can't tune the physics engine to produce the exact desired effects.
     
  3. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    You could try setting the velocity directly.
    The animated invisible box should really work. (Make sure that the box has a kinematic rigidbody though)
     
  4. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    Yes, I would use rigidbody.velocity = ... That has worked well for me when I need to deviate from natural physics.
     
  5. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    I would do some code like this:

    Script for your box:
    Code (csharp):
    1.  
    2. var conveyor : GameObject;
    3.  
    4. private var touchingConveyor = false;
    5.  
    6. function Update ()
    7. {
    8.     if(touchingConveyor)
    9.     {
    10.         conveyorScript = conveyor.GetComponent(Conveyor);
    11.         if(conveyorScript) transform.translate conveyorScript.direction *  conveyorScript.speed * Time.deltaTime;
    12.     }
    13. }
    14.  
    Script for your Conveyor:
    Code (csharp):
    1.  
    2. var direction = Vector3.zero;
    3. var speed = 0.00;
    4.  
    5. function OnTriggerEnter (collider : Collider)
    6. {
    7.     script = collider.GetComponent(Movable);
    8.     if(script)
    9.     {
    10.         script.touchingConveyor = true;
    11.         script.conveyor = gameObject;
    12.     }
    13. }
    14.  
    15. function OnTriggerExit (collider : Collider)
    16. {
    17.     script = collider.GetComponent(Movable);
    18.     if(script) script.touchingConveyor = false;
    19. }
    20.  
     
  6. Samantha

    Samantha

    Joined:
    Aug 31, 2005
    Posts:
    609
    Thanks for the help, everyone! The ideas were great, and I am definitely altering the velocity directly. What seems to be working best, though, is after a collision occurs, I am casting a ray downward to see if my piece is still above the conveyer belt. If it is, I'm adding velocity.

    I'll publish a webplayer when I'm at a decent phase of the prototype.