Any idea why can't I use enum as a variable?

@Needle Engine Assistant

from this script.

const boardAreaComponent = boardAreaTransform.getComponent(BoardArea);

I can’t use directly getComponent from boardAreaTransfrom! it’s error is shown below.

Property ‘getComponent’ does not exist on type ‘Object3D’.ts(2339)

by user 151660356224286721

Here is what I found for you :brain: Discord

I see, it seems there is an issue accessing the getComponent method directly from the Object3D. To resolve this issue, you can call the getComponent method on a GameObject instance rather than on the Object3D. Here’s the corrected code:

import { Behaviour, GameObject, Object3D, serializable } from "@needle-tools/engine";

export class MovementManager extends Behaviour {
  @serializable(Behaviour)
  public boardAreaList?: BoardArea[];

  @serializable(Behaviour)
  public boardArea2x2Matrix?: BoardArea[][] | undefined;

  @serializable(GameObject)
  public boardPrefab?: GameObject;

  InitBoardArea() {
    this.boardPrefab?.children.forEach(child => {
      child.children.forEach(boardAreaTransform => {
        const gameObject = boardAreaTransform.gameObject;
        const boardAreaComponent = gameObject.getComponent(BoardArea);
        if (boardAreaComponent) {
          this.boardAreaList?.push(boardAreaComponent);
        }
      });
    });
  }
}

In this code, we access the gameObject property from the boardAreaTransform to get the corresponding GameObject instance, and then call the getComponent method on that GameObject instance to retrieve the BoardArea component.

0 messages left GPT 3.5
thread_bQ3fzLLgKb9EY2teLyXwmrHZ
Thanks for your feedback!

@Needle Engine Assistant
Is there a way to write transform.gameObject by chance?

by user 151660356224286721

You have reached your limit of 5 messages… please try again in a few hours

Transform and Gameobject are the same thing in needle engine. There is no such thing as a transform component as in unity. Just use this.gameObject

thank you !

by user 151660356224286721

@Needle Engine Assistant
how do i change world space to local space in needleengine?

by user 151660356224286721

Here is what I found for you :brain: Discord

To convert world space coordinates to local space in Needle Engine, you can use the worldToLocal method provided by the Object3D class. If you have a Vector3 representing a position in world space, you can apply this method to a particular object to get the equivalent local space coordinates.

Here’s an example of how to use it:

import { Vector3, Object3D } from "three";

// Assuming 'worldPosition' is a Vector3 representing a position in world space
// and 'object' is an instance of Object3D (e.g., your gameObject).
// Convert worldPosition to object's local space
const worldPosition = new Vector3(/* x, y, z values in world space */);
const localPosition = object.worldToLocal(worldPosition.clone());

The clone method is used to avoid modifying the original worldPosition. Now, localPosition contains the coordinates relative to the object’s local space. Remember that object can be any instance of Object3D, including this.gameObject in the context of a Behaviour component.

4 messages left GPT 4
thread_bQ3fzLLgKb9EY2teLyXwmrHZ
Thanks for your feedback!

this.gameObject.worldposition is another way to get or set the world position

@marcel :cactus:
how do I set them?

by user 151660356224286721

by user 151660356224286721

image.png

thank you so much !

by user 151660356224286721

you should see all options here
image.png

why is mine not showing? do i have to important something different?
image.png

by user 151660356224286721

which needle engine version arem you using?

you dont need to import anything else no

image.png

by user 151660356224286721