Hey guys,
I am trying to get a spell system working on a project, basically I have a crosshair in the center of the screen and when the player attempts to cast a spell I do a raycast from camera.ScreenPointToRay here is the code chunk that does this and I then send the hitInfo to the spellOrigin point, which is just a blank gameobject and have it do a transform.lookat(hitInfo.point)
Vector3 forward = transform.TransformDirection (Vector3.forward);
Vector3 point = new Vector3 (Screen.width * .5f, Screen.height * .5f, 0);
RaycastHit hitInfo;
Ray ray = camera.ScreenPointToRay(point);
Physics.Raycast(ray, out hitInfo, 50f);
now this seems to work perfectly when shooting at something farther away from the player, but if the player is right up against a wall it tends to freak out and shoot the spell at an upward angle, im assuming its because the hitpoint is above and slightly behind the spellOrigin so it makes it look up and backwards.
Is there any simple way to fix this? or is there an easier method of spawning a spell that will go to the crosshairs in the middle of the screen?
Thank you for your time and considerations.
↧