You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description:
I am experiencing an issue where I cannot programmatically move an object if the object has GameControls and a following camera attached in Spline. The issue does not occur when GameControls is not added to an object.
Steps to Reproduce:
Add GameControls and a following camera to an object (e.g., a sphere) in the Spline editor.
Export the scene and integrate it into a React application using react-spline.
Attempt to programmatically move the object using a reference and updating its position property.
Expected Behavior:
The object should move to the new position when its position property is updated programmatically.
Use Case:
The use case for this functionality is to reload the same scene with a button click, where the game object appears at a different coordinate. This would be achieved using the onLoad function to set the initial position of the object.
Actual Behavior:
The object’s position does not change, even though the position values are updated.
Code Example:
"use client";importNavbarfrom"@/components/navigation/Navbar";importReact,{useRef}from"react";importSplineScenefrom"./SplineScene";constHome=()=>{constsplineRef=useRef(null);constsphereRef=useRef(null);functiononLoad(spline){splineRef.current=spline;constsphereObject=spline.findObjectByName("Sphere");if(sphereObject){console.log("Sphere object:",sphereObject);sphereObject.position.x=-400;sphereObject.position.z=-8000;sphereRef.current=sphereObject;// Save the sphere object to the ref}}constmoveObj=()=>{if(sphereRef.current){sphereRef.current.position.x+=10;// Move the sphere along the x-axisconsole.log("Moved Sphere to:",sphereRef.current.position);}};return(<mainclassName="w-screen h-screen"><Navbar/><divclassName="relative w-screen h-screen"><SplineSceneonLoad={onLoad}/><buttononClick={moveObj}className="absolute bottom-10 left-40 bg-green-500 text-white px-4 py-2 rounded">
Move Sphere
</button></div></main>);};exportdefaultHome;
The text was updated successfully, but these errors were encountered:
I found a solution to the issue. Essentially, what I've done is go into the Spline editor and make a group called GameObject and inside the group have the camera and the game object with the game controls attached to a sphere.
So then, in my code, when I find the object by name GameObject, I'm actually finding the group and moving the group, which by default will also move the game object. The game object naturally is going to carry along with the camera. This code works, but I'm wondering if this is how it's always going to be or if there are further ways to improve this?
"use client";importReact,{useRef}from"react";importSplineScenefrom"./SplineScene";constOnLoadMoveCamera=()=>{constsplineRef=useRef(null);constgameObjectRef=useRef(null);constonLoad=(spline)=>{splineRef.current=spline;constgameObject=spline.findObjectByName("GameObject");// GameObject is a group containing Camera + Sphere(GameControls)if(gameObject){gameObjectRef.current=gameObject;gameObject.position.y+=200;gameObject.position.x+=100;}};return(<mainclassName="w-screen relative justify-center flex h-screen"><SplineSceneonLoad={onLoad}/></main>);};exportdefaultOnLoadMoveCamera;
Description:
I am experiencing an issue where I cannot programmatically move an object if the object has
GameControls
and a following camera attached in Spline. The issue does not occur whenGameControls
is not added to an object.Steps to Reproduce:
GameControls
and a following camera to an object (e.g., a sphere) in the Spline editor.react-spline
.position
property.Expected Behavior:
The object should move to the new position when its
position
property is updated programmatically.Use Case:
The use case for this functionality is to reload the same scene with a button click, where the game object appears at a different coordinate. This would be achieved using the onLoad function to set the initial position of the object.
Actual Behavior:
The object’s position does not change, even though the position values are updated.
Code Example:
The text was updated successfully, but these errors were encountered: