x


How to prevent objects from going through each other when using mouse?

I have a mesh that has a box collider and a rigidbody. I use a mouse to move that mesh. I also rotate that mesh with the mouse wheel. Script looks something like this now:

    }

function Update () {
    var pyoritaKatta = Input.GetAxis("Mouse ScrollWheel");
    transform.Rotate(100*pyoritaKatta * kadenKaantymisherkkyys * Time.deltaTime, 0, 0);

    var liikutaKattaX = Input.GetAxis("Mouse X");
    var liikutaKattaY = Input.GetAxis("Mouse Y");

    transform.Translate(liikutaKattaX * kadenLiikutusnopeusX * Time.deltaTime, liikutaKattaY * kadenLiikutusnopeusY * Time.deltaTime, 0,Space.World);
}

When I put a sphere with rigidbody to fall on top of the mesh, I can move the mouse so fast the sphere goes right through the mesh.

The other problem is the mouse controlled mesh can go through walls with colliders.

I can't use Character Controller because it apparently comes with its own collision sphere.

more ▼

asked Mar 26 '12 at 06:36 PM

laskiapina2 gravatar image

laskiapina2
0 2 3 3

(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

Using Translate and Rotate will put things where you say, they won't care about collision. You either need to implement OnCollisionEnter on those objects and have them inform this script to stop, or probably better, use the RigidBody functions MovePosition and MoveRotation

more ▼

answered Mar 26 '12 at 07:20 PM

DaveA gravatar image

DaveA
26.8k 153 171 257

Do I still have to use some kind of collision detection to stop the mesh from moving when I'm using Rigidbody's MovePosition? Because replacing Translate with those didn't help. It still can get other rigidbodies to move when touching, but it itself won't stop when hitting a wall.

The other problem was with mouse sensitivity. Because if I want to use that, the mouse can move so fast, it just passes the other rigidbody meshes.

Mar 27 '12 at 05:46 AM laskiapina2

Try implementing OnCollisionEnter and have it access your 'move' script or SendMessage to tell it to stop moving.

Mar 27 '12 at 07:00 PM DaveA

I have tried to get this to work but there's no hope. I use:

function OnCollisionEnter(collision : Collision) { if (collision.rigidbody) {} else { osuuSeinaan = true; }

and if osuuSeinaan is false, I try to rigidoby.moveposition, but can't get the Input.GetAxis("Mouse X") to that command. When there's no variables but numbers in rigidbody.moveposition, it still goes through the wall.

Mar 28 '12 at 06:00 AM laskiapina2
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2584
x1002

asked: Mar 26 '12 at 06:36 PM

Seen: 871 times

Last Updated: Mar 28 '12 at 06:00 AM