Hi I want to rotate a AR gameobject and scale it like it is working in the browser but not in AR
Hello ASHUTOSH YADAV! To rotate and scale a game object in an AR context using Needle Engine, you typically manipulate the object’s transform properties in your AR component.
Here’s a simple outline of what you generally need to do:
- Determine which object you want to manipulate in your AR space.
- Create a component that scales and rotates the object over time or based on user input.
- Use the appropriate API calls to adjust scaling and rotation.
Pseudocode:
- Create a new AR component.
- Access the target AR game object.
- In the update loop:
- Apply rotation transformation.
- Apply scaling transformation.
Example Code:
import { Component, Transform } from "@needle-tools/engine";
class RotateAndScaleAR extends Component {
start() {
this.targetTransform = this.getComponent(Transform);
this.rotationSpeed = 1; // Rotation speed in degrees
this.scaleFactor = 1.01; // Scale factor
}
update(deltaTime) {
// Rotate the object
this.targetTransform.rotation.y += this.rotationSpeed * deltaTime;
// Scale the object
this.targetTransform.scale.x *= this.scaleFactor;
this.targetTransform.scale.y *= this.scaleFactor;
this.targetTransform.scale.z *= this.scaleFactor;
}
}
Make sure that you have attached this component to the correct object in your AR scene. Also, check whether the AR session is set up correctly, as sometimes issues can arise from that aspect.
If you encounter any specific issues with this implementation or if something isn’t working as expected, please share the details!
3 replies left
thread_Z5q4EQ4HzVhA8k2l2tpk59wq
Reply to this message to continue the conversation
i want to rotate with touch left to right and for scale i want to pinch
Hi, have you disabled usePlacementAdjustment
on the WebXR component?
Make sure it’s enabled