Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 dmroz · Jan 02, 2018 at 03:52 PM · cameraplayerendgame

When character falls out of camera view end or reset game

i am making a similar version of doodle jump and want to know how would i go about making the game end when the character falls out of the camera fov,

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by RustyCrow · Jan 02, 2018 at 04:02 PM

Well i am not so sure if it is pure math. Check this out MonoBehaviour.OnBecameInvisible()

Leaving some code here if you(or interested people) want to try this method.

 // Scripct needs to be attached to the gameobject with the rendrer(I assume you are using sprite rendrer)
     public GameObject PlayerGameObject;
 
     void OnBecameInvisible() 
     {
         Destroy(PlayerGameObject);
     }

another thing to note this method also counts the editor cam so use maximize on play to get the full effect, now i also think you should add some delay maybe time based or distance like mentioned before.
If you still want to calculate the "when i leave the cam view " i would search for calculating view(assuming orthographic) and not the actual position of the cam, makes it more dynamic if you choose to increase or decrease view size. Hope this helps you @dmroz

Comment
Add comment · Show 1 · Share
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 OneCept-Games · Jan 02, 2018 at 04:14 PM 0
Share

I agree, but I would prefer doing a Y value comparison and check when it is 100 units below the camera, and then call the GameOver or LifeOneDown method.

avatar image
0

Answer by OneCept-Games · Jan 02, 2018 at 03:54 PM

That would be pure math to calculate when your player is out of vision, but much easier just to do a comparison of your camera- and player Y value (assuming you are in 2D view, and using an XY plane

 if (cam.transform.position.y > player.transform.position.y + 100)
 ...
Comment
Add comment · Show 2 · Share
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 dmroz · Jan 02, 2018 at 04:24 PM 0
Share

i have never used that so i don't even know where to put that in the code and is it in player or the camera or the level itself

avatar image OneCept-Games dmroz · Jan 02, 2018 at 07:30 PM 0
Share

You could put such a check in your Update() function of a script you add to the Player object. void Update() { if (this.transform.position.y-100 < Camera.main.transform.position.y) { GameOver(); } }

avatar image
0

Answer by dmroz · Jan 02, 2018 at 07:41 PM

used the method @OneCept-Games gave me and it seemed to not work with the code i used.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Fall : MonoBehaviour {
     public Player player;
     public Camera camera1;
    
 
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     void Update () {
         if (camera1.transform.position.y > player.transform.position.y + 100)
         {
             Application.Quit();
         }
     }
 }
 
Comment
Add comment · Show 5 · Share
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 dmroz · Jan 02, 2018 at 07:53 PM 0
Share

this is on an empty game character as i thought this would work

avatar image OneCept-Games · Jan 02, 2018 at 07:58 PM 0
Share

Try adding Debug.Log(player.transform.position.y); to see what happens to y-value. if your character falls, either y or z should change accordingly, and you can see what value would be most close to when out of sight.

avatar image dmroz OneCept-Games · Jan 02, 2018 at 08:09 PM 0
Share

yeah did that and changed the value to -10 on both y and z switching between both and still not working

avatar image OneCept-Games dmroz · Jan 02, 2018 at 08:13 PM 0
Share

Is it a 2D or 3D project?

Show more comments

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.

Follow this Question

Answers Answers and Comments

124 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 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 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 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 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 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

Animation automatique personnage 0 Answers

Locking world rotation of child 1 Answer

3d Sound when the player near and not the camera? 1 Answer

Walk animation for camera isn't playing 1 Answer

How you change another script value smoothly on trigger 0 Answers


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