Hi,
I have tried to make interior with some furnitures and I would like to move them everywhere.
The problem is all object are going pass through on each other.
I tried these:
- mesh collider (Convex, Is Trigger and without)
- box collider (Convex, Is Trigger and without, Physic material and without)
- rigidbody with, and without (with gravity and Is Kinematic and without)
With rigidbody is better, but I don’t need realistic physic.
Any Idea?
Thx.
http://www.csongorfekete.com/Unity_web_player/Terberendezo_v1.html
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(BoxCollider))]
public class drag_mouse : MonoBehaviour
{
private Vector3 screenPoint;
private Vector3 offset;
void OnMouseDown()
{
screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
void OnMouseDrag()
{
if(Input.GetKeyDown(KeyCode.A))
transform.Rotate(0, 90, 0);
float distance_to_screen = Camera.main.WorldToScreenPoint(gameObject.transform.position).z;
Vector3 pos_move = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance_to_screen ));
transform.position = new Vector3( pos_move.x, transform.position.y, pos_move.z );
}
}
I tried with simple cube. I would like to move them with mouse without pass through.
On the next I need snaps to objects…
Any Idea?
Thanks.
That’s because the way you move them, if you set it’s position directly, then it’s not going to respect collision.
Unfortunately I can’t give directly, because I need to move any very in the room with mouse, but You have localise the problem. Thx.
I have tried this and I’m a little closer to final. The problem is I need box collider not sphere collider.
using UnityEngine;
using System;
using System.Collections.Generic;
public class SuperCharacterController : MonoBehaviour {
[SerializeField]
float radius = 0.5f;
private bool contact;
// Update is called once per frame
void Update () {
contact = false;
foreach (Collider col in Physics.OverlapSphere(transform.position, radius))
{
Vector3 contactPoint = col.ClosestPointOnBounds(transform.position);
Vector3 v = transform.position - contactPoint;
transform.position += Vector3.ClampMagnitude(v, Mathf.Clamp(radius - v.magnitude, 0, radius));
contact = true;
}
}
}