Home › Forums › General Questions › Question about using OrbitControls for Child Camera
- This topic has 13 replies, 3 voices, and was last updated 10 months, 4 weeks ago by qiangge.
-
AuthorPosts
-
2023-12-30 at 8:18 am #69408aqiangCustomer
Hello everyone!
I have a question about using OrbitControls to manipulate a camera that is a child of a group. When the group is at the origin, everything works fine with the orbit controls. However, when the group is moved away from the origin (you can click on the robot object to move it forward), the orbit control for rotating the scene becomes uncontrollable. I’ve tried various solutions without success, and I suspect it might be necessary to modify the source code of OrbitControls. I’m seeking help from the experts on the forum. The demo has been provided in the link.I hope the orbit of the orbit will always be centered around the robot
Thank you!
- This topic was modified 10 months, 4 weeks ago by aqiang.
Attachments:
You must be logged in to view attached files.2023-12-30 at 9:55 am #69411kdvParticipantAdd the
TrackTo
constraint and it will work like here https://v3d.net/ps8 (use WASD to move).Or you can use this puzzle after moving your model. Set the time value to 0.
Puzzles and JS coding. Fast and expensive.
If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.
2023-12-30 at 12:57 pm #69412qianggeParticipantGreat! This is the effect I wanted, thank you, KDV! Is this constraint set up in 3D software beforehand? Because I couldn’t find this part in the JavaScript logic. Could you display the key code or logic for this? My confusion is, if the character and the camera are not grouped, how does the camera follow the character? The target point of the camera can be constrained to the position of the character. Can you please advise on how to set up the camera? Thanks again, KDV.
2023-12-30 at 1:13 pm #69413kdvParticipants this constraint set up in 3D software beforehand?
I just added that constraint in Blender.
The camera is a child for an object you want to move and it moves together with its parent. The
TrackTo
constraint forces the camera to look at its parent at any moment.Puzzles and JS coding. Fast and expensive.
If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.
2023-12-30 at 2:53 pm #69415qianggeParticipantI used 3dsMax, and the principle should be the same as what you described. I tried both methods, and the result is similar to the demo I provided earlier. The camera follows the parent object and always faces the target object, which is correct. However, the issue arises when the target object moves away from the origin—the orbit path becomes strange. Could it be a bug specific to the Max version?
Attachments:
You must be logged in to view attached files.2023-12-30 at 3:14 pm #69418kdvParticipantIn fact, your scene’s camera has no controls at all. You add Orbit controls later in
visual_logic.js
. Why? Can’t you export you scene with Orbit controls chosen in 3Dmax?Puzzles and JS coding. Fast and expensive.
If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.
2023-12-30 at 3:38 pm #69419kdvParticipantCould it be a bug specific to the Max version?
Maybe, have no idea. In Blender it’s much easier to do. I juts re-exported you scene and it works with no problems as expected.
https://v3d.net/rp1Puzzles and JS coding. Fast and expensive.
If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.
2023-12-30 at 3:46 pm #69420qianggeParticipantdemo2
I’ve uploaded a demo that uses the default controls with the method I used last night. Please take a look. Shanks KDV- This reply was modified 10 months, 4 weeks ago by qiangge.
- This reply was modified 10 months, 4 weeks ago by qiangge.
- This reply was modified 10 months, 4 weeks ago by qiangge.
Attachments:
You must be logged in to view attached files.2023-12-30 at 4:18 pm #69426qianggeParticipantYes, your Blender export is correct. I had suspected an issue with the matrix transformation in the update function of OrbitControls. if (i.targetObj.updateWorldMatrix(!0, !1).
I hope someone can verify whether this is indeed a bug that exists only in the Max version.
2023-12-30 at 4:27 pm #69427qianggeParticipanthadBugDemo
Posts lost, resend the demo.- This reply was modified 10 months, 4 weeks ago by qiangge.
2023-12-30 at 4:50 pm #69429kdvParticipantYou have “Camera001.Target” parented to “pepole”. Thus the position of “Camera001.Target” is always (0, 0, 0). This object is an orbit center.
app.controls.targetObj
shouldn’t have any parent or its parent should be the scene itself. It should have position in the world’s coordinates. Have no idea why in Max it’s exported this way.Puzzles and JS coding. Fast and expensive.
If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.
2023-12-30 at 5:52 pm #69430kdvParticipantIf you can’t add the constraint in Max you can do it using JS code.
Puzzles and JS coding. Fast and expensive.
If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.
2023-12-31 at 3:39 am #69433qianggeParticipantfor KDV,Thank you for your splendid contribution!
-
AuthorPosts
- You must be logged in to reply to this topic.