#Topdown 2D Physics Raycast - Dynamic Footsteps

1 messages · Page 1 of 1 (latest)

cyan heath
#

I'm trying to convert this script made for a 3D game for my 2D topdown project that creates dynamic footsteps based on the tilemap terrain Tag. The main goal is - by using FMOD - to make the code read the tilemaps with "Ground" Layer that the Player is on, and change the Fmod Event calls using that tilemap specific name Tag (wood, grass, carpet). The issue is that I must use a RaycastHit2D instead of RayCastHit but this kinda ruins at line 94.

#

This script is attached to the Player and the animations have events that call the PlayRunEvent and WalkRunEvent instances.

#

Can someone please help me

amber pivot
#

What exactly is the problem? Just change that raycast to an appropriate physics2d function and use raycasthit2d instead.

cyan heath
#

I've changed all the lines regarding raycast physics but I get the following error: F_CharFst.cs(94,69): error CS1615: Argument 3 may not be passed with the 'out' keyword

Lines I changed:
Line 8:

private RaycastHit2D rh;

Line 94:

if (Physics2D.Raycast(transform.position, Vector2.down, out rh, distance, lm))
#

I don't know how to pass the raycast rh value into the Physics2D.Raycast function

amber pivot
#

first of all, if we're talking about top down 2d and you want to "cast down"(into the screen), a raycast probably wouldn't work.

#

And for your error, have a look at the docs. I imagine 2d raycast arguments and return type are somewhat different from 3d ones.

#

the 2d one seems to return the hit instead of outing it as an argument

cyan heath
#

Can't I raycast at the Z axis with something like Vector3.forward?

amber pivot
#

No, you can't that's why it's raycast 2d. It's always in the XY plane

#

Check the other methods in Physics2D. I've seen a couple that might work for you.

#

like point overlap

cyan heath
#

Okay, thanks for the tip. I'll give it a try tomorrow