Jump to content

[HELP] Camera move a circel


iwalidza

Recommended Posts

Posted
2 minutes ago, iwalidza said:

its not work with me and i need code not tool
or any help

the resource is not compiled, you can check the code and adapt it on your server

Posted

Hello iwalidza,

if you want to have the camera move around in a circle around a point then you can simply use the math.sin and math.cos functions of Lua in combination with MTA's setCameraMatrix function :) 

local cam_move_start = getTickCount();
local cam_radius = 50;
local cam_move_circle_duration = 15000;
local cam_move_angle_start = 0;
local cam_movearound_point_x = 0;
local cam_movearound_point_y = 0;
local cam_movearound_point_z = 0;
local cam_height_offset = 20;

local function get_camera_point_circular()
  local now = getTickCount();
  local passed_time = now - cam_move_start;
  local progress_circle = passed_time / cam_move_circle_duration;
  
  local cam_current_angle = math.rad(cam_move_angle_start + progress_circle * 360);
  
  local cam_pos_x = cam_movearound_point_x + cam_radius * math.cos(cam_current_angle);
  local cam_pos_y = cam_movearound_point_y + cam_radius * math.sin(cam_current_angle);
  
  return cam_pos_x, cam_pos_y, cam_pos_z + cam_height_offset;
end

addEventHandler("onClientPreRender", root, function()
    local cam_pos_x, cam_pos_y, cam_pos_z = get_camera_point_circular();
    
    setCameraMatrix(cam_pos_x, cam_pos_y, cam_pos_z, cam_movearound_point_x, cam_movearound_point_y, cam_movearound_point_z);
  end
);

(code has not been tested)

The math.cos and math.sin functions are used to model a circle in math. You should learn about those in your school math classes. Extended knowledge can be gained in University which I highly recommend to attend to!

- Martin

  • Thanks 1

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