Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Dose anyone know how RaycastHit.Distance works?

A topic by The Spellsmith created Aug 16, 2020 Views: 180 Replies: 3
Viewing posts 1 to 4
Submitted

I am working on a 2D game where when the player goes in a direction they will go all the way to the collider there and then stop I am plaining to use RaycastHit.distance to get how far away they are and move the player that much but I cannot figure out how  to receive the distance as a variable

Submitted (2 edits)

You're using a function for 3D world physics (PhysX), you want RaycastHit2D (Box2D) instead: https://docs.unity3d.com/ScriptReference/RaycastHit2D-distance.html
There's also Vector2.Distance(object1.transform.position, object2.transform.position) function just in case. Good luck with your thing there, Spellsmith.

Submitted

Thanks for the help, good luck with your game as well!

Try

Vector3.Distance((RaycastHit variable).point, player.transform.position)