- Home /
Get collision position for particle effect on static object like wall
Hi, I need help for detecting the position of collision when my bullet (using raycast) collide with a wall in order to instantiate a particle effect on that position facing toward my player. I already tried to read some other post like this but since my target is a static object like walls, chairs and etc, I don't think it is a good idea to use onTriggerEnter. So is there any other way to do it? So far I only manage to get the particle on the starting position of the object, not the position of the collision and the rotation is also not facing my camera.
Answer by highpockets · Apr 09, 2019 at 12:20 PM
You should be using hit.point not hit.transform.position.
For having it face the player, point it in the opposite direction of your raycast
Hello, thank you for your reply. it works perfectly. But I want to ask regarding the direction. Actually I have already figure it out using Quaternion.LookRotation(-mainCam.transform.forward)
but I also watch a tutorial saying Lookat code should also work but when I tried it return error cannot change from void to quaternion. Would you please help me figure it out? I am still learning Unity so excuse my curiosity.
LookAt and LookRotation are essentially the same thing but LookAt is a function of Transform. LookAt internally does rotations as quaternions and then changes the transform direction based on the transform and up hint vector passed to the function, but it just rotates toward the target and does not return anything. Since it doesn’t return anything, it is a void, LookRotation does the same thing, but it returns a quaternion that you would apply to the transforms rotation:
LookAt()
effect.transform.LookAt(player.transform);
LookRotation()
transform.rotation = Quaternion.LookRotation(player.transform.position - hit.point);