Quantcast
Channel: Questions in topic: "follow"
Viewing all articles
Browse latest Browse all 536

Smooth Follow 2D simple tweak

$
0
0
I've applied this standard assets script to my camera and it's actually doing a good job but since my background texture is placed inside a quad that "follows" the player and not the camera at higher movement speed the camera gets too far or too much behind the player and gets out of view. Since I never programmed in JS I'd like to ask you how should I tweak this code to stop the script from moving the camera if the velocity is over (for example) 5f. I tried to change it this way : var target : Transform; var smoothTime = 0.3; private var thisTransform : Transform; private var velocity : Vector2; function Start() { thisTransform = transform; } function Update() { if(velocity.x > 5f) //in C# I'd do it this way, but apparently velocity.x = 5f; //if velocity gets past 5, it doesn't remain 5 thisTransform.position.x = Mathf.SmoothDamp( thisTransform.position.x, target.position.x, velocity.x, smoothTime); thisTransform.position.y = Mathf.SmoothDamp( thisTransform.position.y, target.position.y, velocity.y, smoothTime); }

Viewing all articles
Browse latest Browse all 536

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>