playMaker

Author Topic: [SOLVED] Raycast - Direction problem  (Read 3147 times)

ermak

  • Junior Playmaker
  • **
  • Posts: 60
    • AL Games
[SOLVED] Raycast - Direction problem
« on: June 02, 2015, 02:54:33 PM »
Hello,




I want "Raycast Direction" to point at Vector3 Target Object.
I am not sure where exactly is the problem... maybe "Direction" is correct, but angle
is not the same as target object.

With "Debug Line" action everything wotking fine.




How I can make "Raycast Direction" like a "Debug Line"?
« Last Edit: June 03, 2015, 05:32:21 AM by ermak »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Raycast - Direction problem
« Reply #1 on: June 02, 2015, 03:36:02 PM »
Raycast wants a Direction and you're giving it a Position.

The direction is (enemyPosition - playerPosition).normalized. You can get both positions, subtract one from the other. Normalize it, then input that.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

ermak

  • Junior Playmaker
  • **
  • Posts: 60
    • AL Games
Re: Raycast - Direction problem
« Reply #2 on: June 03, 2015, 05:31:10 AM »


Hello,
It works! Thanks!

But I have one question more. Without "Vector3 Normalize" action working too.
Normalize must be used or it's optional?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: [SOLVED] Raycast - Direction problem
« Reply #3 on: June 03, 2015, 06:58:46 AM »
When normalized, a vector keeps its direction but the magnitude is 1. So the result is like 0.2, 0.2, 0.6 or something whereas before normalization it may have been 20.0, 20.0, 60.0.

Vectors can be very tricky. If you are working with them I would recommend reading a bit about how they work and what you can do with them. It takes some getting used to if you didn't study them in math.

http://docs.unity3d.com/ScriptReference/Vector3.Normalize.html
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D