Jump to content

[QUESTION] setElementRotation and getCameraMatrix.


Recommended Posts

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 by Exilepilot
Link to comment
34 minutes ago, myonlake said:

You can use the findRotation function to do that.

You've made my day :D 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 by Exilepilot
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...