# 3D Attributes in a 2D game

**URL:** <https://qa.fmod.com/t/3d-attributes-in-a-2d-game/20534>\
**Category:** FMOD Engine\
**Tags:** cpp\
**Created:** [August 11, 2023, 11:57pm UTC](https://qa.fmod.com/t/3d-attributes-in-a-2d-game/20534 "2023-08-11T23:57:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmcmorris](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jmcmorris/32/5406_2.png) [@jmcmorris](https://qa.fmod.com/u/jmcmorris)\
**Post date:** [August 11, 2023, 11:57pm UTC](https://qa.fmod.com/t/3d-attributes-in-a-2d-game/20534/1 "2023-08-11T23:57:40Z")

</div>

Hello! I’ve been having trouble getting the spatial positioning of 3D sound events to work correctly in my c++ game engine. I believe I’m simply misunderstanding something and it is likely a simple fix.

My game is a 2D platformer with positive X axis being right and positive Y axis being down. I’ve been trying to set things up properly so that the sounds are positioned correctly in FMOD. I originally tried forward vector being {1, 0, 0} and up vector being {0, -1, 0} but that resulted in all sounds events to only be on the x axis and y and z are always 0. This is going off of what we see in the FMOD Studio profiler. I’m happy to go into more detail but honestly am not sure what else to provide. Thanks!

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [August 16, 2023, 4:06am UTC](https://qa.fmod.com/t/3d-attributes-in-a-2d-game/20534/2 "2023-08-16T04:06:34Z")

</div>

Hi,

I would expect a positive forward vector and a negative up vector to work, which makes me suspect that the 3D attributes of the events are being set incorrectly. Could I get you to provide a code snippet of how you are passing your engine’s coordinates to FMOD with [Studio::EventInstance::set3DAttributes](https://www.fmod.com/docs/2.02/api/studio-api-eventinstance.html#studio_eventinstance_set3dattributes), and any other transformations you are making to the coordinates for this purpose?

You may also wish to check yourself what the coordinates are in your engine and compare them to the coordinates retrieved using [Studio::EventInstance::get3DAttributes](https://www.fmod.com/docs/2.02/api/studio-api-eventinstance.html#studio_eventinstance_get3dattributes) to check for any discrepancies.

---

<div class="post-metadata">

**Author:** ![jmcmorris](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jmcmorris/32/5406_2.png) [@jmcmorris](https://qa.fmod.com/u/jmcmorris)\
**Post date:** [August 18, 2023, 2:37am UTC](https://qa.fmod.com/t/3d-attributes-in-a-2d-game/20534/3 "2023-08-18T02:37:34Z")

</div>

Hey Leah, thanks for the response. Here’s what the code looks like for when I setup my listener attributes.

```auto
s_fmod3DAttributes.forward = FMOD_VECTOR {1.0f, 0.0f, 0.0f};
s_fmod3DAttributes.up = FMOD_VECTOR {0.0f, -1.0f, 0.0f};
s_fmod3DAttributes.position.x = position.x;
s_fmod3DAttributes.position.y = position.y;
s_system->setListenerAttributes(0, &s_fmod3DAttributes);

```

and here is where I set my event instance

```auto
FMOD_3D_ATTRIBUTES attributes {};
attributes.position.x = position.x;
attributes.position.y = position.y;
attributes.position.z = 0;
attributes.forward = FMOD_VECTOR {1.0f, 0.0f, 0.0f};
attributes.up = FMOD_VECTOR {0.0f, -1.0f, 0.0f};
eventInstance->set3DAttributes(&attributes);

```

I checked EventInstance::get3DAttributes and it is returning what I’m putting in. Does any of the above code look wrong? Thanks!

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [August 23, 2023, 2:00am UTC](https://qa.fmod.com/t/3d-attributes-in-a-2d-game/20534/4 "2023-08-23T02:00:24Z")

</div>

The issue here appears to be that the forward vector is being set incorrectly to the X direction. Even though your up vector is flipped, the forward vector should still be in the Z direction. Given my unfamiliarity with your engine, I’m not sure whether a positive or negative Z direction forward vector is appropriate, but try both and see which one works.

---

<div class="post-metadata">

**Author:** ![jmcmorris](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jmcmorris/32/5406_2.png) [@jmcmorris](https://qa.fmod.com/u/jmcmorris)\
**Post date:** [August 23, 2023, 2:51am UTC](https://qa.fmod.com/t/3d-attributes-in-a-2d-game/20534/5 "2023-08-23T02:51:02Z")

</div>

Thank you Leah! This was indeed the issue. Here is what I ended up with given my coordinate system.

```auto
attributes.forward = FMOD_VECTOR {0.0f, 0.0f, -1.0f};
attributes.up = FMOD_VECTOR {0.0f, -1.0f, 0.0f};

```

---

<div class="post-metadata">

**Author:** ![tlconflict](https://avatars.discourse-cdn.com/v4/letter/t/4491bb/32.png) [@tlconflict](https://qa.fmod.com/u/tlconflict)\
**Post date:** [April 29, 2024, 4:44pm UTC](https://qa.fmod.com/t/3d-attributes-in-a-2d-game/20534/6 "2024-04-29T16:44:28Z")

</div>

```auto
attributes.forward = FMOD_VECTOR {0.0f, 0.0f, -1.0f};
attributes.up = FMOD_VECTOR {0.0f, -1.0f, 0.0f};

```

So this is for the event instance 3d attributes, is your listeners forward and up vectors the same too? I’m having the same problem

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [May 8, 2024, 11:32pm UTC](https://qa.fmod.com/t/3d-attributes-in-a-2d-game/20534/7 "2024-05-08T23:32:29Z")

</div>

> [@tlconflict](#):
>
> So this is for the event instance 3d attributes, is your listeners forward and up vectors the same too? I’m having the same problem

Just to clarify, what positive/negative direction is your coordinate system using for each axis? Are you using the same setup as @jmcmorris?

---

<div class="post-metadata">

**Author:** ![tlconflict](https://avatars.discourse-cdn.com/v4/letter/t/4491bb/32.png) [@tlconflict](https://qa.fmod.com/u/tlconflict)\
**Post date:** [May 9, 2024, 1:51am UTC](https://qa.fmod.com/t/3d-attributes-in-a-2d-game/20534/8 "2024-05-09T01:51:02Z")

</div>

The same yeah. Really the issue was because I was not passing null for attenuation position: [Top down 2D spatial sounds - #4 by tlconflict](https://qa.fmod.com/t/top-down-2d-spatial-sounds/21552/4)
