- Home /
Camera bounce/collision
I wanted to make my camera collide with walls,i was looking for script on Internet but found many useless, i want just simple script. I was trying to use Raycast but it doesn't work as it should, so i created my own method and it works preety well, but when i stand near wall camera start bouncing (it is zooming in and out, in and out...), any ideas how to fix that? I tried delaying zoomout function but it still doesn't look well.
Here is my script:
var right_camera : GameObject;
private var collisionCount = 0;
function Update () {
if (collisionCount > 0)
ZoomIn();
if (collisionCount == 0)
ZoomOut();
}
function OnTriggerEnter () {
collisionCount++;
}
function OnTriggerExit () {
collisionCount--;
}
function ZoomOut () {
var step = 3 * Time.deltaTime;
transform.localPosition = Vector3.MoveTowards(transform.localPosition, right_camera.transform.localPosition, step);
}
function ZoomIn () {
var step = 10 * Time.deltaTime;
transform.localPosition = Vector3.MoveTowards(transform.localPosition, Vector3(-1,2,0), step);
}
Answer by Gamershaze · Nov 15, 2014 at 02:20 AM
Well from what I can see, you don't have any logic here to make it stand still. Let me see if I can explain.
You're checking if..
I'm touching something or not.
Oh, I am. Zoom in!
Am I touching something now?
Nope, zoom out!
Am I touching something now because I zoomed out?
Yes, zoom in!
Repeat
This constantly going in a loop, where it zooms in when touching something, and zooms out when it doesn't. Which would result in this crazy zoom-in/zoom-out situation you mentioned. Hope I explained.
Yes i know that, the question is how to edit this script to work better. Raycasting doesn't work as it should,it detects collision even if there is no collision.
Your answer
Follow this Question
Related Questions
Camera Question 0 Answers
3rd Person Cam Collides when it shouldn't 1 Answer
Camera looking through objects when touching 1 Answer
How can I change camera when colliding with "X" object? 1 Answer
Camera collision problem 1 Answer