Hi,
I’m having a problem with raycasting and object colliding and not a clue what it is.
It’s difficult to explain, so I’ve uploaded my sample project. This is the link:
https://drive.google.com/open?id=0B8Gqj5xq7RSnaUlGNjFUM0JJcVE
The problem is the following:
when the player gameObject shoots a bullet, the ray the bullet casts is perpendicular to the bullet instead of being in the same path as the bullet. That causes the collisions not to work as expected.
This is a screen capture of the view from above that shows what I’m talking about.
I thought that how the projectile’s ray was being instantiated in the Projectile.cs class (line 93) could be the problem.
So I tried changing that from this…
Ray ray = new Ray (transform.position, transform.forward);
to this…
Ray ray = new Ray (transform.position, Vector3.forward);
When doing that, the enemy diagonal to the player is actually hit. BUT the enemy that’s positioned in z=0 isn’t: the bullet just goes through him.
Again, not sure why the raycasts are perpendicular to the bullet’s trajectory. I guess that’s the problem but not sure why it happens.
Any ideas?
Thanks in advance!