Ease in out camera script

This forum is currently in read-only mode.
From the Asset Store
Simple and easily editable template for a dynamic camera that zooms in and out based on how far apart the players are.
  • Here is a python script for ease in and out camera motion.

    class myscroll:
    	def __init__(self):
    		self.acceleration=100;		
    		self._ax=0;	self._ay=0
    		self._vx=0;	self._vy=0
    
    	def __call__(self, obj):
    		myscrollx=(System.ScrollXLeft+System.ScrollXRight)/2
    		myscrolly=(System.ScrollYTop+System.ScrollYBottom)/2
    
    		# x motion
    		diff=obj.X-myscrollx
    		if abs(diff)<1:
    			self._ax=0;  self._vx=0
    		else:
    			if self._vx**2/(2*self.acceleration) >= abs(diff):
    				self._ax=-1*cmp(self._vx,0)*self.acceleration
    			else:
    				self._ax=cmp(diff,0)*self.acceleration
    
    		# y motion
    		diff=obj.Y-myscrolly
    		if abs(diff)<1:
    			self._ay=0;  self._vy=0
    		else:
    			if self._vy**2/(2*self.acceleration) >= abs(diff):
    				self._ay=-1*cmp(self._vy,0)*self.acceleration
    			else:
    				self._ay=cmp(diff,0)*self.acceleration
    
    		self._vx+=self._ax*System.TimeDelta
    		self._vy+=self._ay*System.TimeDelta
    		System.ScrollX(myscrollx+self._vx*System.TimeDelta)
    		System.ScrollY(myscrolly+self._vy*System.TimeDelta)
    myscroll=myscroll()[/code:2fwplqvv]
    No need to understand how it works, just have that script run at the "start of layout" and call "myscroll(Sprite)" every tick.  The only setting is acceleration, which can be changed at any time with the script "myscroll.acceleration=400".
    
    Basically what it does is accelerate the camera to the object and then decelerate so that when the screen arrives at the object the camera speed will be zero.
    
    Example of use: [url]http://dl.dropbox.com/u/5426011/examples/camera%20easeinandout.cap[/url]
    req at least 0.99.84
    
    Feel free to use or enhance.
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • That's a really nice effect, great work! I bet it'd look good combined with a slight pan out when moving and a pan inwards when motionless.

    Really cool, thanks for sharing

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)