DezOnlyOne Posted April 27, 2016 Share Posted April 27, 2016 I have an application where I have an FPS like camera that moves around a scene. I want to be able to use a camTo function to move the player around the scene. I have a position v3 and target v3. If I do not have a rotation value, the camera is not looking at the target. Is there a way to calculate the rotation knowing the position of the camera and the position of the target. Is my approach to this incorrect? How do I correctly move my freecamera to the correct location and ensure that it is looking at my desired target? Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted April 27, 2016 Share Posted April 27, 2016 There are ways to do this without caring about all that. Either use a followCamera (third person camera), or a subclass of TargetCamera (practically all but ArcRotateCamera) & set the target. There is some trigonometry to assign rotation to camera, but I do not understand why you would move your camera to the "correct" location. If it is a first person camera, the user has already moved it to where they want to view from. Quote Link to comment Share on other sites More sharing options...
DezOnlyOne Posted April 27, 2016 Author Share Posted April 27, 2016 47 minutes ago, JCPalmer said: There are ways to do this without caring about all that. Either use a followCamera (third person camera), or a subclass of TargetCamera (practically all but ArcRotateCamera) & set the target. There is some trigonometry to assign rotation to camera, but I do not understand why you would move your camera to the "correct" location. If it is a first person camera, the user has already moved it to where they want to view from. Sorry, I can explain further. The user can walk around in a big warehouse and view whatever they want, but if they want to move quickly to a specific object instead of "walking" over, or up stairs, they can select the object from an index that will make them appear in front of the object. Does this make sense? Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted April 27, 2016 Share Posted April 27, 2016 Ok, FreeCamera is a subclass of TargetCamera. After you change the camera location, you could set the target to what you want to look at. Sounds like you would only want to do that for one frame. Putting something to change one frame later is a pain. Try: camera.lockedTarget = lookAtMesh; camera._getViewMatrix(); camera.lockedTarget = null; Quote Link to comment Share on other sites More sharing options...
DezOnlyOne Posted April 27, 2016 Author Share Posted April 27, 2016 This worked great. Thanks for all your help. JCPalmer 1 Quote Link to comment Share on other sites More sharing options...
DezOnlyOne Posted April 28, 2016 Author Share Posted April 28, 2016 Sorry, I spoke too soon. After testing a little further I realized this is not working correctly. Part of the room I have is a spiral ramp with several plaques on the wall. As you are transported to each of the plaques, I notice that the target is getting further and further away. I setup a babylonjs playground with 4 spheres as targets, and 4 boxes as their corresponding camera positions. The camTo function works fine to move the camera position. I just need to be able to look at the ball. You can uncomment which ever POV you want to use at the bottom. When you load this, you won't see anything because the ball(and other objects are behind you. but if you just hit the down arrow to back up or turn around with the mouse drag, you will see that it is there. http://www.babylonjs-playground.com/#Y7QTM#3 Thanks for all your help Quote Link to comment Share on other sites More sharing options...
DezOnlyOne Posted April 29, 2016 Author Share Posted April 29, 2016 Using setTarget worked fine. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.