playMaker

Author Topic: Raycasting in line of crosshair  (Read 3006 times)

JayySkull

  • Playmaker Newbie
  • *
  • Posts: 3
Raycasting in line of crosshair
« on: July 30, 2014, 03:03:51 PM »
Hi there, currently designing a third person game using playmaker. I have a question which should have a simple solution but i have no idea to go about it.

Currently i have a gameobject called "crosshair" which draws a gui texture onto the screen while having a raycast being casted from the centre of the main camera the problem is casting it straight from the centre being a third person perspective the ray is being cast directly through the player i've tried solving this by offsetting where the ray is cast by creating an empty gameobject through which to cast the ray. with all that being said all of the methods end up with the ray and the crosshair being out of line in all situations any help would be GREATLY appreciated.

-Thanks
Edit: Also this a third person shooter so accuracy is key .
« Last Edit: July 30, 2014, 03:17:27 PM by JayySkull »

redikann

  • Full Member
  • ***
  • Posts: 174
Re: Raycasting in line of crosshair
« Reply #1 on: July 30, 2014, 03:23:35 PM »
So your shooting a ray from the center of your cam but this doesn't mean it has to originate from the center of your cam. You could very easily parent an empty to your cam, zero out it's translation and then push it forward( away from the cam and in front of the player). Then you could have the ray originate from this object. Don't forget to tell the action which axis to project the ray in.

JayySkull

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Raycasting in line of crosshair
« Reply #2 on: July 30, 2014, 03:29:48 PM »
Thanks for the speedy reply,

I have tried parenting empty game objects and casting a ray from its origin maybe i should have given more details on what i'm trying to achieve . what i'm really after is getting an offset from the player and have a crosshair that is always in line with the raycast. also, i'm using kgf orbitcam from the asset store .
« Last Edit: July 30, 2014, 03:32:57 PM by JayySkull »

redikann

  • Full Member
  • ***
  • Posts: 174
Re: Raycasting in line of crosshair
« Reply #3 on: July 30, 2014, 03:54:39 PM »
I also use and prefer the KGF camera. While the camera itself doesn't offer built in off setting they're ways to do this. You could parent an empty to your character and then set it as the target for the camera. You can also set the player collider to avoid ray cast.
A lot of times with Actions if you use "From Game Object" and From Position" fields the position field will become an offset. I don't know if this works for raycast because it doesn't imply it in the description.

JayySkull

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Raycasting in line of crosshair
« Reply #4 on: July 30, 2014, 04:47:46 PM »
Ok, i've set the raycast to exclude the "Player" layer. The raycast can't be offset by the "From Position" property it's one or the other and setting a target object for kgf camera results in weird orbiting around the player character, so instead i've created and parented an empty gameobject called "RaycastPos" to the camera and offset by 1 on the X axis and 0.5 on the Y. it seems to be doing the job ok. Any ideas on how to ensure that the crosshair and raycast are always positioned in line ?
« Last Edit: July 30, 2014, 05:00:56 PM by JayySkull »