Jump to content

And now: math!:D


Maurize

Recommended Posts

So I'm trying to let the camera rotate at a specific object( means x, y and z coordinate ) with setCameraMatrix and onClientRender.

Anybody a hint how to let camera rotate at this coordinates?

I mean, I only have to update this: setCameraMatrix( this, this, this, this not( x ), this not( y ), this not( z ) )

Thanks!(:

Link to comment
local x, y, z = 0, 0, 10         -- Camera position 
local rotation = 0               -- Camera rotation 
local height = math.rad ( 1 )    -- height 
local distance = 19              -- default distance from the player 
  
function renderCameraRotation ( ) 
    rotation = ( rotation + 0.5 ) 
    if ( rotation >= 360 ) then  
        rotation = 0 
    end 
  
    local angle = math.rad ( rotation ) 
    local camX = ( x + 3 * distance * math.cos ( angle ) * math.cos ( height ) ) 
    local camY = ( y + 3 * distance * math.sin ( angle ) * math.cos ( height ) ) 
    local camZ = ( z + 0.4 * distance + 2 * distance * math.sin ( height ) ) 
    local hit, hitX, hitY, hitZ = processLineOfSight ( x, y, z, camX, camY, camZ, false, false, false ) 
    if ( hit ) then 
        camX, camY, camZ = ( x + 0.9 * ( hitX - x ) ), ( y + 0.9 * ( hitY - y ) ), ( z + 0.9 * ( hitZ - z ) ) 
    end 
    setCameraMatrix ( camX, camY, camZ, x, y, z ) 
end 
addEventHandler ( "onClientPreRender", root, renderCameraRotation ) 

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