#Adding scripts to objects
1 messages · Page 1 of 1 (latest)
Hello there – we have an experimental AI bot 🤖 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...
Hello Aya Ali,
I'm here to assist you with technical questions. To help you with the spinning cube issue, I would need to see the relevant code you've used to create and attempt to spin the cube.
Please share the code snippet where you're setting up the cube and trying to apply the rotation logic. Just the screenshots won't be sufficient for me to diagnose the issue—you can copy and paste the code here or describe in detail what methods or properties you are using to spin the cube.
Remember that when working with rotation in Needle Engine, you typically would modify the rotation properties of the object3D component within the update lifecycle method of a component attached to that cube. If you can provide the code, I can give you more specific advice.
1 messages left GPT 4
thread_0uXHAosgEr381dyrP8m7kRaB
Thanks for your feedback!
Have you added the component to the cube and do you get your log from start() in the browser console?
yeah, I watched this video https://www.youtube.com/watch?v=uf5UK0bLHlY&t=82s and did the same thing
This video gives a short introduction to the easiest and fastest way to create custom Needle Engine components in Unity
📚 Documentation: https://docs.needle.tools
✨ Website: https://needle.tools
💬 Discord: https://discord.needle.tools
#threejs #webgl #webxr #unity
No, I have Nothing in the console
Can you show a screenshot of the selected cube in your Unity scene where the inspector is also visible?
And also please in the browser
- open the dev console
- reload the page
- send a screenshot of the console
Is the script actually on the cube? Not visible on the screenshot
It is not
That’s what I meant here. If you want that script to do something with that cube, add it to the cube
How to do that I mean I added it here
Scripts are just pieces of code. They need to be added to objects to do something with those objects.
- select the cube in the scene
- in the inspector, scroll down and click Add Component
- find your Rotate component and add that
If you have multiple objects that you want to rotate them each of them would have the „ Rotate“ script attached with its own settings (for example different rotate speeds)
I want to make the camera rotate but I can't attach it in code I tried to do some thing like this this.gameObject.getComponent(Camera)
But I couldn't control it
Is that even possible?
The camera is another object in your scene. If you want to affect it add your component to the camera gameObject. You’ll see that it already has the „OrbitControls“ component which does the default camera controls you see in the browser
You can add your own component to it and you can also remove the OrbitControls if you want to completely control it by your component.
There are also ways to reference components from other objects but I recommend you start with the basics 🙂
yeah, What I want just to make the camera move by using the keyboard Input
So, I will take your advice
You can take a look at this sample for an example of a camera following a character which is controlled by keys
https://engine.needle.tools/samples/sidescroller/?overlay=samples&room=needle801
Yeah, exactly I want the camera move like the player