Jump to content

camera zoom script


swipis
 Share

Recommended Posts

Hello,

I trying to make zoom in/out 3rd person camera, here is the code:

if mouseWheelPos > 0 then
if self.camDist < self.camMaxDist then
self.camDist = mouseWheelPos * 1
if self.camDist > self.camMaxDist then
self.camDist = self.camMaxDist
numer = self.camMacDist
end
end

elseif mouseWheelPos < 0 then
if self.camDist > self.camMinDist then
self.camDist = mouseWheelPos * 1
if self.camDist < self.camMinDist then
self.camDist = self.camMinDist
number = self.camMinDist
end
end

end
System:Print(tostring(self.camDist))

self.cam:SetPosition(Vec3(0, -self.camDist, 0))

 

I can say its kinda working, but need make more smoother, any tips?

Link to comment
Share on other sites

 

 

 

 

 

I don't know lua but in c++ this works

 

// ----------------------camera zoom

 

float deltazoom = (window->KeyDown(Key::Up) - window->KeyDown(Key::Down))*Time::GetSpeed()*0.05;

float zoom = camera->GetZoom() + deltazoom;

zoom = Math::Clamp(zoom, 0.2, 10.0);

camera->SetZoom(zoom);

 

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Link to comment
Share on other sites

So how does one clamp zooming then as I suppose that's the next question when zooming with a 3rd person camera. I notice the z value keeps going so simply doing a max/min on the position used creates a stickiness. I suppose maybe reset each frame or keep an offset.

 

Although window:SetMousePosition(x, y, 0) doesn't seem to actually reset z to 0.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...