Adding collision to Raycast hit
Im testing around with destruction atm. I downloaded something from assets store called "Fracture - LITE"
Now, Fracture - LITE needs a collision to activate the fractureing of a objekt, let's say, if i shoot a sphere at the (in this case) box, it will shatter. And i only have a force on my raycast right now, that will puch the box away, but it won't shatter. (except when it hits the ground again, but i want it to shatter on impact)
So, anyone know how to add a collision impact when my raycast hits the objekt?
using UnityEngine;
using System.Collections;
public class RayCast_Shooting_Script : MonoBehaviour
{
public int force = 1000;
void Update ()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width/2, Screen.height/2,0));
if(Input.GetMouseButtonDown(0))
{
if(Physics.Raycast(ray,out hit,100))
{
Vector3 forward = transform.TransformDirection(Vector3.forward) * 10;
Debug.DrawRay(transform.position, forward, Color.green);
if (hit.rigidbody != null)
{
hit.rigidbody.AddForce(ray.direction * force);
}
}
}
}
}
Can you post the script that does the shattering in Fracture - LITE? You could probably do some hack-y thing like instantiate a tiny object with a collider at the hit point of the raycast to collide with the object you want to shatter, but it might make more sense to just slightly modify the Fracture - LITE script to allow you to initiate the shattering in a different way.
Actually, I just checked the asset store and it seems you don't get the source code with the free version. I guess the hack-y method will have to do...
Your answer
Follow this Question
Related Questions
Raycast not detecting hit 4 Answers
How to freeze an GameObject on x axis in specific direction? 1 Answer
How do you detect a mouse button click on a Game Object? C# 2 Answers
Make raycast ignore hitbox? 0 Answers
RayCast not working , why ??? 0 Answers