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 ShadeZ94 · Jul 08, 2011 at 10:42 AM · animationplayercollide

When Colliding With Animation, Player Re-spawns And Keeps Moving.

I am making a game for my ITS Class. I have made an Animation which is meant to be a "Moving Wall" in which if the "Player" collides with it, the "Player" re-spawns at the start of the Map.

The "Player collides and re-spawns but when it re-spawns the "Player" keeps moving forward and i can't stop it.

I have tried everything i know (Which is not much as i am relatively new to Unity :P) and searched the Forums but have not found an answer.

My thanks to anyone who can help me with my problem =).

 *Edit*

Player Controller

 var speed = 500.0;
 var rotateSpeed = 1.0;
 var bulletPrefab:Transform;
 var bulletSpeed = 20000.0;
 
 var bullet1Prefab:Transform;
 var bullet1Speed = 20000.0;
 private var dead = false;
 //function OnControllerColliderHit(hit : ControllerColliderHit)
 function OnTriggerEnter (hit:Collider)
 {
     if(hit.gameObject.tag == "Fallout")
     {
     dead = true;             
     Application.LoadLevel (1);
     }                
     if(hit.gameObject.tag == "EnemyBullet")
     {
         Destroy (hit.gameObject);
         dead = true;
     //subtract life here
         HealthControl.LIVES -= 1;
     }
            
         if(hit.gameObject.tag == "AniWall")
        {
     
             dead = true;
              //subtract life here
              HealthControl.LIVES -= 1;
         }
 }
 
 function Update ()
 {
     var controller : CharacterController = GetComponent(CharacterController);
     // Rotate around Y - Axis
     transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
     // Move forward / backward
     var forward = transform.TransformDirection(Vector3.forward);
     var curSpeed = speed * Input.GetAxis ("Vertical");
     controller.SimpleMove(forward * curSpeed);
     if(Input.GetButtonDown("Fire1"))
     {
         var bullet = Instantiate(bulletPrefab, GameObject.Find("SpawnPoint").transform.position, Quaternion.identity);
         var bullet1 = Instantiate(bulletPrefab, GameObject.Find("SpawnPoint1").transform.position, Quaternion.identity);
     
     bullet.rigidbody.AddForce(transform.forward * bulletSpeed);
     bullet1.rigidbody.AddForce(transform.forward * bullet1Speed);
     }
 }
 
 function LateUpdate()
 {
     if(dead)
     {
         transform.position = Vector3(-991.336,46.12195,-775.5392);
         gameObject.Find("Main Camera").transform.position = Vector3(10,4,-20);
         dead = false;
     }
 }        
 @script RequireComponent(CharacterController)
Comment
Add comment · Show 2
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 Joshua · Jul 08, 2011 at 10:53 AM 0
Share

There must be something in either your respawn or your playermovement code that causes this behaviour. Post it and maybe we can help.

avatar image ShadeZ94 · Jul 08, 2011 at 11:01 AM 0
Share

Sorry about the formatting, i am not sure how to type the code here properly :P.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Joshua · Jul 08, 2011 at 11:11 AM

Don't worry about the formatting, I fixed it.

When he collider with the fallout you set 'dead' to true, and then load up scene( 1 ). All of the other code won't get run, because every object in your scene will be destroyed and replaced by the new scene. If the player then 'keeps moving forward', that is because that's the way you coded it in your new scene - there's nothing in this script that could cause that because this script gets destroyed upon levelload, and a new instanstance is created for the player in that new scene.

If you want this script to 'survive' scenechanges add DontDestroyOnLoad() to it.

If you want the lateUpdate() if( dead ) to be run, don't change the scene until it has.

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 ShadeZ94 · Jul 08, 2011 at 11:25 AM 0
Share

Thank you for your reply and the formatting. I will test this now. $$anonymous$$any thanks.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to let the player collide with animated objects? 0 Answers

Trail of color behind the player 2D c# 1 Answer

Idle Animations, Player Walking 0 Answers

How to move player after animation 2 Answers

Can I make animations snap to a frame? 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