Jump to content

Camera matrix to velocity direction


Gallardo9944

Recommended Posts

Okay i found it out myself. Posting the code if someone needs:

local vehicle = getPedOccupiedVehicle(localPlayer) 
local mx,my,mz,mpx,mpy,mpz = getCameraMatrix() 
local vector = {mx-mpx,my-mpy,mz-mpz} 
setElementVelocity(vehicle,-vector[1],-vector[2],-vector[3]) 

It doesn't calculate the difference between velocities, but in fact it does set the direction.

Link to comment
It doesn't calculate the difference between velocities, but in fact it does set the direction.

If you still need to make it only set velocity to 1 in the direction, then divide the components of the vector with the length (normalization)

local vehicle = getPedOccupiedVehicle(localPlayer) 
local mx, my, mz, mpx, mpy, mpz = getCameraMatrix() 
local dist = getDistanceBetweenPoints3D(mx, my, mz, mpx, mpy, mpz) 
local vector =  
{ 
    (mx - mpx) / dist, 
    (my - mpy) / dist, 
    (mz - mpz) / dist 
} 
setElementVelocity(vehicle, -vector[1], -vector[2], -vector[3]) 

It may give better result if you use the vehicle position and camera position instead of camera position and camera target position.

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...