0

Unity version: 2018.3.2f1

When I throw my ball against the wall, a decal projection spawned on the spot where the ball collides. This goes well until the ball touches the wall and the ground at the same time. The decal projector is then spawned incorrectly, so that the red spot does not come out nicely on both surfaces

As you can see in the screenshots below, I know that the decal has to stand at an angle against the wall so that it is also projected onto the ground. Only I have no idea how I can do this

I now ensure that when the ball touches a layer with the tag "col", it is exactly at the point where the ball collides it places a decal projector. I would like to know how I can also have these placed obliquely

Decal spawned wrong PNG

Decal spawned wrong video

This is what I want when it hits the wall and floor: This is wat I want

public Camera cam;
public Transform sphere;
public float distanceFromCamera;
Rigidbody r;
public GameObject decalPrefab;

// Start is called before the first frame update
void Start()
{
    distanceFromCamera = Vector3.Distance(sphere.position, cam.transform.position);
    r = sphere.GetComponent<Rigidbody>();
}

Vector3 lastPos;
// Update is called once per frame
void Update()
{
    if (Input.GetMouseButton(0))
    {
        Vector3 pos = Input.mousePosition;
        pos.z = distanceFromCamera;
        pos = cam.ScreenToWorldPoint(pos);
        r.velocity = (pos - sphere.position) * 10;
    }
}

void OnCollisionEnter(Collision col)
{
    if (col.gameObject.tag == "col")
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;
        if (Physics.Raycast(ray, out hitInfo, 100000f))
        {
            Instantiate(decalPrefab, col.contacts[0].point, Quaternion.FromToRotation(Vector3.up, col.contacts[0].normal));
        }
    }
}

}

0 Answers0