Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Kuro Okami · Nov 11, 2014 at 07:55 AM · collisionwaitforseconds

Wait for seconds on collision

So I'm trying to create a script that will, on collision wait for 1/10th of a second and then zero the player velocity, speed etc (I'm doing this because otherwise the player spins of in a random direction with the force applied beforehand). How do I do this in C#.

This is my script so far:

 using UnityEngine;
 using System.Collections;
 
 public class Player1 : MonoBehaviour {
 
     public float directionalSpeed = 7.5f;
     public float rotationalSpeed = 5f;
     void Start () {
     }
 
     // Update is called once per frame
     void Update () {
         transform.Translate(Vector3.right * (-Input.GetAxis("Vertical")) * Time.deltaTime * directionalSpeed);
         transform.Translate(Vector3.down * Input.GetAxis("Horizontal") * Time.deltaTime * directionalSpeed);
         transform.Rotate(Vector3.forward * 10 * Input.GetAxis("Rotate") * Time.deltaTime * rotationalSpeed);
 
     }
     void OnCollisionEnter(Collision c)
     {
         transform.Translate (Vector3.zero);
     }
 }
 

Any suggestions?

Comment
Add comment · Show 3
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 prof · Nov 11, 2014 at 09:01 AM 0
Share

that code is awful. Anyway coroutine

avatar image Kuro Okami · Nov 11, 2014 at 09:09 AM 0
Share

Thanks, also, I'm self-taught and still at high school so I still have a lot to learn about with not much free time.

avatar image prof · Nov 11, 2014 at 10:30 AM 0
Share

I'm also self-taught(not at high school though). $$anonymous$$eep coding) Physics

1 Reply

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

Answer by Gardosen · Nov 11, 2014 at 09:09 AM

Hello Kuro,

for everything where you want to use a waiting timer, you can use this http://docs.unity3d.com/ScriptReference/Coroutine.html

also if i see it correctly, you are doing all 3 calls on the update, even when it can be that only one is really needed. i recommend you to make a ifelse or a switchcase before it to really only call the fuctions you want to get called, instead of calling all.

Greetings Gardosen

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 Kuro Okami · Nov 11, 2014 at 10:04 AM 0
Share

Thanks, the top 3 transforms are for the movement and rotation of the player, I just decided to put the two parts in one script.

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

28 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

Related Questions

How to use OnCollisionEnter, OnCollisionStay and OnCollisionExit 2 Answers

I need help making it so my countdown trigger timer doesn't start until the entire rigid body is inside the trigger 2 Answers

How to delay time reset on collision? 2 Answers

im trying to make it if a specific item collides with a cube it flashes red but it keeps comming up with an error 2 Answers

Trigger Animation after Wait For Seconds 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