playMaker

Author Topic: Raycast always aiming at player? [SOLVED]  (Read 1779 times)

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
Raycast always aiming at player? [SOLVED]
« on: August 20, 2014, 03:55:10 PM »
Hey everyone, it's been a while!

I have an enemy and I'm setting up AI for it. I want the enemy to constantly send a raycast towards the player, and if it hits the player (if the enemy can "see" the player,) then the enemy will begin other AI procedures.

Right now, I store the player's position every frame and then use that variable as the "direction" for the raycast. But, strangely, the raycast shoots off into space, not towards the player at all. I'm hoping this is something silly I'm missing, if anyone can help guide, push, shove, or kick me in the right direction that would be great! :D


« Last Edit: August 20, 2014, 04:19:39 PM by Breadman »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Raycast always aiming at player?
« Reply #1 on: August 20, 2014, 04:04:34 PM »
Direction is a vector3 as a direction, not a vector3 as a transform position. It expects a normalized vector3 in that field, such as 0,0,1 (forward in self space).

Try Raycast 2 for a gameobject target.

http://hutonggames.com/playmakerforum/index.php?topic=5406.msg28956#msg28956

I'm still working on it.. I don't think I have a forum thread for it yet, but it's on the Ecosystem if you rather get it there.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
Re: Raycast always aiming at player?
« Reply #2 on: August 20, 2014, 04:19:28 PM »
Works like a charm, thank you!! Wasn't expecting such a tidy solution - usually my approach is somewhat ham-fisted  :P

Thanks a ton. Lunch is on me if you're ever in LA!