Hello!, How can I change / acces InstantateOptions?

I’m trying to create a drag and drop system for items. I want to use a stamp object and a ghost object. The ghost object shows placable space and the stamp object is moved with drag interactions.

Now I want to instantiate a new object at the ghost position and after placing I want the ghost and stamp object to return to their original place.
I have this custom script:

Original Post on Discord

by user 365574199844274177

Hello there – we have an experimental AI bot :robot: that might be able to help you with your question. Would you like to try this out?

How it works:
Reply to the messages of the bot that end with a thread_id to interact with it and ask follow-up questions. You can also mention the bot directly in this channel to get help.

Help requested: please wait a moment…

To clarify your requirements and proceed with creating a component for your drag and drop system, I would need more details:

  1. The behavior of the ghost object: How does it indicate placable space? Does it turn a different color or does it have some kind of highlight?
  2. The specific events that trigger the ghost and stamp objects to return to their original positions.
  3. Any limitations or specific interactions you want to include or exclude in the drag and drop process.
  4. How you check if the placement is valid in the space represented by the ghost object.
  5. Any additional conditions for instantiation of the new object, such as constraints related to the environment or other objects.

Please provide this additional information so that I can help create the appropriate component for Needle Engine.

1 messages left GPT 4
thread_TtM1uMcKc3MKe5m4EMXqfMXX

  1. The ghost object is an empty gimmick with a transparent material. I want to add the option to turn red if it hits other alread placed objects in the future.
    2.OnPointerUp should trigger the placement of the item if possible and return the stamp and ghost.
  2. I want to include that the stamps are only draggable when the player has enough money for placing the stamp object.
  3. It has a predefinec boundary, they have the same parent so it’s local.
  4. I want to include that if the ghost hits another tower or path collider the tower should not be able to spawn. Also the money thing later.

by user 365574199844274177

Here is what I found for you :brain: Discord

Given these specifications, you can create a custom component in Needle Engine to implement the drag and drop system with the described behaviors. Here’s a pseudocode outline for the custom script to achieve the drag and drop functionality with the requirements specified:

*thread_TtM1uMcKc3MKe5m4EMXqfMXX*

typescript
import { Vector3, Raycaster, Color } from “three”;
import { Behaviour, GameObject, AssetReference, RaycastOptions } from “@needle-engine/engine”;

export class DragAndDropComponent extends Behaviour {
private initialStampPosition: Vector3; // Initial position of the stamp object
private ghostObject: GameObject; // Reference to the ghost object
private stampObject: GameObject; // Reference to the stamp object

awake() {
this.initialStampPosition = this.gameObject.worldPosition.clone(); // Store the initial stamp position
this.ghostObject = /* Reference to the ghost object /;
this.stampObject = /
Reference to the stamp object */;
}

start() {
this.addPointerEventListeners();
}

addPointerEventListeners() {
this.context.inputSystem.addPointerListener(“up”, this.onPointerUp.bind(this));
}

onPointerUp(event: PointerEvent) {
if (/* Check if the player has enough money /) {
const raycaster = new Raycaster();
// Define the ray direction based on the event input (e.g., mouse position)
raycaster.setFromCamera(/
Define ray direction based on event input /, this.context.mainCamera);
const intersections = this.context.physics.raycast(raycaster, new RaycastOptions(/
Define layers for filtering if necessary */));

  if (intersections.length > 0) {
    // Check if the intersected object is a valid placement surface
    const isPlacementValid = /* Check if the placement is valid based on the intersection */;

    if (isPlacementValid) {
      // Instantiate a new object at the ghost position
      const newObject: AssetReference = /* Instantiate a new object based on the ghost position */;
      newObject.instantiate().then((instance) => {
        // Handle the successful instantiation
      });

thread_TtM1uMcKc3MKe5m4EMXqfMXX

// Return the stamp and ghost objects to their original positions
this.stampObject.worldPosition.copy(this.initialStampPosition);
this.ghostObject.worldPosition.copy(this.initialStampPosition);
} else {
// Handle invalid placement
}
}
}
}
}

*thread_TtM1uMcKc3MKe5m4EMXqfMXX*

You can adapt this pseudocode to your specific project structure, object references, and raycast logic to implement the drag and drop system with the described behaviors in Needle Engine.

0 messages left GPT 3.5
thread_TtM1uMcKc3MKe5m4EMXqfMXX
Thanks for your feedback!

This was not helpful since copying this is not so nice.

I just need to know how I can Instantiate at a specific location in a specific parent object

by user 365574199844274177

newObject.instantiate().then((instance) => {
// Handle the successful instantiation
}); <— this

by user 365574199844274177

You can use something like this:

newPrefab.worldPosition = yourwp
desiredParent.add(newPrefab)
ghost.worldPosition = startpos

omg vectors in three.js are a mess

by user 365574199844274177

it sill did not work, but thanks

by user 365574199844274177

I was looking for this:

opts.position = this.worldPosition;
opts.rotation = this.worldQuaternion;
opts.context = this.context;
this._currentCount += 1;

        const newInstance = GameObject.instantiateSynced(this.object as GameObject, opts) as GameObject;
        console.assert(newInstance !== this.object, "Duplicated object is original");
        this.object.visible = false;

by user 365574199844274177

If you parent the object with this code to anything that is not in the root of your scene the “worldPosition” will not be correct. What do you mean by it still didnt work? What exactly?

Since opts.position is localspace

I’m sorry for the confusion. I can’t really explain it well. But it seems to work almost like I want now. I use the duplicate component and I made a custom component to spawn a ghost if in boundary of field.

Now when I release my duplicate copies the position of the ghost exactly like I want.

by user 365574199844274177

The duplicate has as parent the context

by user 365574199844274177

and the ghost has aswell

by user 365574199844274177