Quantcast
Channel: Latest Questions by esitoinatteso
Viewing all articles
Browse latest Browse all 92

Raycast Ray ray origin problem

$
0
0
Hi there! I'm having a problem calling a Raycast to handle projectiles. I type Physics.Raycast(Ray ray,out RayCastHit hitInfo, float Distance) and then a problem occurs. What I'm trying to do with my Raycast, is to originate it from my player position. So I state that Ray ray = new Vector3 ( my player's x,y,z). That line gives Error CS0029: cannot implicitly convert type " UnityEngine.Vector3" to "UnityEngine.Ray". Now, I thought Ray ray was supposed to be a Vector3, so what's wrong? Please, since Raycasts aren't that easy and I'm just a beginner, try to be as clear as possible in your answers... Thanks for the patience! EDIT: My Script now is this if(Input.GetKeyDown(KeyCode.Space)){ RaycastHit hitInfo; if(Physics.Raycast(transform.position, transform.forward,out hitInfo, rayDistance)){ Debug.Log (" Raycast Doing Good"); } } It's working, and it's stored in the Update Function of my Player' Script. I'd like to know how to get the same result when I Raycast from another script and I still want to origin my ray from my Player GameObject position. I tried to store my player position in static variables to call them with Player.myPlayerPositionX and the likes, with no success at all. IF I declare a new Public Static originRay(myPlayerPosition) where myPlayerPosition is a Vector3 I can then place the Raycast in the update of another script not related direcly with my Player GameObject and call this originRay in Ray ray = originRay... if that's right I've got my answer. Thanks for the feedback!

Viewing all articles
Browse latest Browse all 92

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>