• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by eshonbel · Apr 21, 2014 at 05:37 PM · cameracollisionrigidbodycollider

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 $$anonymous$$s 2D scripts and converting them. Everyt$$anonymous$$ng 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 t$$anonymous$$s for initialization
     void Start () {
     animator = transform.GetComponentInC$$anonymous$$ldren<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, ($$anonymous$$s original script) credit to $$anonymous$$m and $$anonymous$$s channel.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image EvilTak · Apr 22, 2014 at 03:16 AM 0
Share
avatar image eshonbel · Apr 22, 2014 at 07:29 AM 0
Share
avatar image Hoeloe · Apr 22, 2014 at 07:58 AM 1
Share
avatar image eshonbel · Apr 22, 2014 at 03:29 PM 0
Share

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Camera gets flung off of the map when the player collides with certain objects. 0 Answers

OnCollisionEnter of Projectile detects parent with rigidbody instead of child objects with collider 2 Answers

Rigidbody colliders 1 Answer

Having trouble with rigidbody collisions on mesh/terrain colliders 0 Answers

My Character controller is being push a little bit when i'm about the get the coins. How can i possibly detect collision and destroy the coins without actually getting affected by the colliding physics? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges