Using udonSharp, I’m trying to detect when an object impacts with a user. I tried the below code and it isn’t working. I tried using OnPlayerCollisionEnter but that didn’t do anything.
This udon behavior is added to the object that has sphere collider, vrc pickup, rigidbody, VRC Object Sync, particle system and the audio source.
You will see I’m setting gravity in the code. This was a failed attempt at trying to stop the object from falling through the ground. Now it doesn’t even throw either. So I’m having two problems, I guess.
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
using VRC.SDK3.Components;
public class SnowBall : UdonSharpBehaviour
{
private VRCObjectSync _sync;
private Rigidbody _rb;
private AudioSource _ac;
private ParticleSystem _particles;
void Start()
{
_ac = GetComponent<AudioSource>();
_rb = GetComponent<Rigidbody>();
_sync = GetComponent<VRCObjectSync>();
_particles = GetComponent<ParticleSystem>();
}
private void showParticles(){
_particles.Play();
_ac.Play();
}
public override void Interact()
{
_sync.SetGravity(true);
_rb.useGravity = true;
}
public void OnPlayerCollisionEnter(VRCPlayerApi player) {
if(!player.isLocal){
showParticles();
}
}
public void OnCollionEnter() {
showParticles();
}
}