Exilepilot Posted April 5, 2018 Share Posted April 5, 2018 (edited) Problem: When given a point P (pX, pY, pZ) how do I set an elements rotation R (rX, rY, rZ) (for example: a rocket projectile) so that the element directly faces the point P? Context: Basically I had an idea for a cruise missile script which involves using the camera matrix and getting the point the camera is directly looking at and setting a rocket projectile's rotation to face it. The idea is to have the rocket's rotation always point where the camera is facing so that eventually the rocket will hit or intersect that point. I have no idea how to solve this problem and I am starting to think nobody does. If anyone knows the solution to this problem could you please explain? [EDIT] The point which the rocket faces may change and therefore the rockets direction needs to change which gives me another question: Does this problem involve velocity as well if the rocket needs to change direction mid-flight? I've tried to explain as clearly as possible. If you need any further context / some sort of example in code please ask. Thanks. Edited April 5, 2018 by Exilepilot Link to comment
myonlake Posted April 5, 2018 Share Posted April 5, 2018 You can use the findRotation function to do that. 1 Link to comment
Moderators IIYAMA Posted April 5, 2018 Moderators Share Posted April 5, 2018 I doing stuff like that with: local camera = getCamera() local matrix = getElementMatrix(camera) local rotX, rotY, rotZ = getElementRotation(camera) 1 Link to comment
Exilepilot Posted April 5, 2018 Author Share Posted April 5, 2018 (edited) 34 minutes ago, myonlake said: You can use the findRotation function to do that. You've made my day Thank you very much, I appreciate such a quick reply. 25 minutes ago, IIYAMA said: I doing stuff like that with: local camera = getCamera() local matrix = getElementMatrix(camera) local rotX, rotY, rotZ = getElementRotation(camera) When I setCameraMatrix and only specify the position of the camera and not the point it's looking at. Can the point the camera is looking at change? For example I want to change the point the rocket is facing onClientRender. Thank you very much. I'll post results. [EDIT] HMM... I just looked into findRotation and I don't think it's enough. It seems only to be used for setPedRotation which is deprecated... I was looking for something such as: local px, py, pz, lx, ly, lz = getCameraMatrix() --[[ Solution to problem... --]] function getRotationFacingTargetPoint(startPoint, targetPoint) --[[ blah blah blah change rotation to face the point ]] return rx, ry, rz end -- Create projectile and guide it towards lx, ly, lz from px, py, pz. local p = createProjectile(localPlayer, 19, px, py, pz, 1, nil, getRotationFacingTargetPoint(px,py,pz,lx,ly,lz)) Edited April 5, 2018 by Exilepilot Link to comment
myonlake Posted April 5, 2018 Share Posted April 5, 2018 (edited) Sorry, perhaps findRotation3D helps you in this case better. Wait, so you're essentially just wanting the camera to point forward? Edited April 5, 2018 by myonlake Link to comment
Moderators IIYAMA Posted April 6, 2018 Moderators Share Posted April 6, 2018 Denny199 his reply is very useful. This will give you everything you need. 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now