wall stop(help!)

hello!

Can someone tell me what is the script for colliding with a wall? If an object drives into the wall, he must not pass the wall.

I am controlling an scissors with the clicks of mouse and if he hits something, i want it not to go pass that object, but still to be able to move or rotate in the opposite direction.

Does it work if the object is trigger?

here is my code for moving the object:

var VitezaMiscare  = 1.0;

function Update () 

{
if (Input.GetButton("Inaintare"))
{
transform.position += -transform.right * VitezaMiscare * Time.deltaTime;
}
}

have you tried selecting the wall and going component / physics / box collider?
you could also try adding the component to the scissors?

dan

the wall has box collider on it, and my object has mesh collider.

Nothing happens, the object goes through the wall.

Setting the position manually always works. You should test/raycast whether there’s a collition or not.

Let me tell you the whole story:

I have a 3D scissors that hat to cut(collide with) a virtual paper. The scissors is opening and closing(of course) but it is rotating as much as i keep the mouse button pressed.
I want it to move just between 2-75 degrees, just like a real one.

So i thought of 2 possibilities:

  1. To make the handle of the scissors the object that the opposite blade has to collide with. And when it hits it, he has to stop, not to go pass it, but still to be able to go back. The same with the other blade. Exactly like a real one.
  2. To set a maximum rotation for the scissors between 2-75 degrees. But still dont know how…

Here is the code for the rotation:

if (Input.GetAxis("Forfecare"))
{
transform.eulerAngles.z += -VitezaRotatieClick * Time.deltaTime;
}

i have to say that the blade and the handle are 2 different objects, grouped. And there are 2 groups, because are 2 handles and 2 blades.This script is applied for the group.
Hope you understood…

what do you mean by test/raycast?

I have a script that registers a collision, and returns 0 on console, but is written for a different object.

function OnTriggerEnter (other : collider)

Does one of your collider objects has a rogidbody component too? If not no collision event will happen. Does your script already has an OnCollisionXXX() event?

yes, both have colliders, and rigid bodies atached.
One with is kinematic and trigger, and other not.

Yes, my script has and OnTriggerEnter event, not OnCollisionXXX. And this event is for my scissors, and made specifically for coliding with the paper.

Then you should be able to check the wall collision too. There is only one exception if your object moves to fast! Then you have to use Physics.Raycast().