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 DAzorn · Jun 15, 2015 at 06:01 PM · cameratimerbobbing

How to give a timing to my script?

Hi all, i create this script to move my cute T-Rex. But i have problem, beacause i want to time (like 2 seconds of timer) the transition between camera position.

Here is the script:

 using UnityEngine;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour {
 
     public float PlayerWalkSpeed = 20.0f;
     public float PlayerRotationSpeed = 80.0f;
     public GameObject View;
     Vector3 ViewOriginalPosition;
     Vector3 ViewBobbingPosition;
     private bool isWalking = false;
 
     // Use this for initialization
     void Start () {
 
         ViewOriginalPosition = new Vector3(0.0f, 291.0f, -47.0f);
         ViewBobbingPosition = new Vector3(0.0f, 311.0f, -47.0f);
     }
     
     // Update is called once per frame
     void Update () {
     
         if (Input.GetKey ("w")) {
             
             transform.Translate ((Vector3.forward) * PlayerWalkSpeed * Time.deltaTime);
             isWalking = true;
         } else if (Input.GetKey ("s")) {
             
             transform.Translate (-(Vector3.forward) * PlayerWalkSpeed * Time.deltaTime);
             isWalking = true;
         }
 
         if (Input.GetKey ("a")) {
             
             transform.Rotate (-(Vector3.up) * PlayerRotationSpeed * Time.deltaTime);
             isWalking = true;
         } else if (Input.GetKey ("d")) {
             
             transform.Rotate (Vector3.up * PlayerRotationSpeed * Time.deltaTime);
             isWalking = true;
         }
 
         if (isWalking == true) {
         
             if(View.transform.localPosition == ViewOriginalPosition){
 
                 View.transform.localPosition = ViewBobbingPosition;
             } else if (View.transform.localPosition == ViewBobbingPosition){
 
                 View.transform.localPosition = ViewOriginalPosition;
             }
         }
     }
 }

Someone can help me? :)

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 Vice_Versa · Jun 15, 2015 at 06:50 PM 1
Share

make a float called timer and give it a value of 2, in the update say timer -= Time.deltaTime;

avatar image DAzorn · Jun 15, 2015 at 10:20 PM 0
Share

That's so easy? ahahaha :)

avatar image Vice_Versa · Jun 16, 2015 at 06:33 PM 0
Share

Did it work? if yes please mark this as answered. if not ill figure it out now

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by mjood-10 · Jun 16, 2015 at 05:41 AM

 var Player : Transform;
 
 var CameraTime = 0.3;
 
 private var mycamera : Transform;
  
 private var cameratrans : Vector2; 
 
 function Start () {
 mycamera = transform;
 
 }
 
 function Update () {
 
 mycamera.position.x = Mathf.SmoothDamp(mycamera.position.x ,Player.position.x ,cameratrans.x ,CameraTime);
 
 mycamera.position.y = Mathf.SmoothDamp(mycamera.position.y ,Player.position.y ,cameratrans.y ,CameraTime);
 
 }

to have smooth move (camera with your cute T-Rex)

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 DAzorn · Jun 16, 2015 at 09:39 AM 0
Share

Thanks, but i need in C# and i don't understand this script in JAVA hahah

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to make camera position relative to a specific target. 1 Answer

How do i know if a animation is finished or not ? 2 Answers

Camera Bob 1 Answer

How do I make a camera bob when I walk? 3 Answers

Mouse looking combined with head bob animation. And key input to play animation 2 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