- Home /
Camera Collision Not Working
I am currently following Quill18Creates' Youtube Tutorial on making a 2D Game; Clony Bird. However, I am creating a FP 3D version and referencing to his 2D scripts and converting them. Everything has gone kind of well until it came down to my camera; my first person. It is a normal camera. I want to make it collide with the pipes and terrain, but it just goes through. I have placed a cube with a collider around it (parented) tried rigidbody and sphere/box colliders (triggered and not triggered). Here is the movement script so far.
using UnityEngine;
using System.Collections;
public class BirdControl : MonoBehaviour {
Vector3 velocity = Vector3.zero;
public Vector3 gravity;
public Vector3 flapVelocity;
public float maxSpeed = 5f;
public float forwardSpeed = 10f;
bool didFlap = false;
Animator animator;
bool dead = false;
// Use this for initialization
void Start () {
animator = transform.GetComponentInChildren<Animator>();
}
void Update () {
if(Input.GetMouseButtonDown(0)) {
didFlap = true;
}
}
void FixedUpdate () {
if(dead)
return;
velocity.z = forwardSpeed;
velocity += gravity * Time.deltaTime;
if(didFlap == true) {
didFlap = false;
if(velocity.y < 0)
velocity.y = 0;
velocity += flapVelocity;
}
velocity = Vector3.ClampMagnitude(velocity, maxSpeed);
transform.position += velocity * Time.deltaTime;
float angle = 0;
if(velocity.y < 0){
angle = Mathf.Lerp(0, -90, velocity.y / maxSpeed);
}
transform.rotation = Quaternion.Euler(0, 0, angle);
}
void OnCollisionEnter(Collision collision) {
animator.SetTrigger("Death");
dead = true;
}
}
Because I'm referencing to quill18creates, (his original script) credit to him and his channel.
$$anonymous$$aybe using rigidbodies will be the best solution. Ins$$anonymous$$d of changing the transform's position, you can add forces to it or change rigidbody.velocity. And please make sure that you don't make your colliders as triggers because then they ignore collisions with rigidbodies.
As stated in the question, I have already tried rigidbodies but with no gravity and which are kinematic. I understand what Is Trigger is, I am just following the video.
Looks like your biggest problem is not understanding what any of these settings do, and yet trying to use them anyway. Ins$$anonymous$$d of just checking options at random, look them up and find out what they do.
$$anonymous$$inematic Rigidbodies do detect collisions, but don't apply the physics step to them, so you won't get the Rigidbody moving after a collision - it will just continue on through it.
It's ALWAYS a good idea to try and understand WHY you're doing something, and WHAT it is you're doing, rather than just following a tutorial blindly.
Thanks for your reply, I unchecked the $$anonymous$$inematic and it worked. I understand the basics of colliders and whatnot, but unfortunately I'm not at the same level as most of all the clever Unity whizzes out there. In the video, he explained that Is $$anonymous$$inematic meant it won't be affected by gravity and stuff. However, he was using 2D Physics. Sorry for my bad question, and if you were to post an answer, I would tick it.