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 mihir solanki · Aug 17, 2014 at 08:05 AM · rotationmovementjavaobject movement

how to make a rotating object move in a specific direction on press of a button?

i want to make a game object (a cube) move in the direction of its head(any corner) when a button is pressed very much like a kite.i am new to controller scripting(i have the basic java knowledge) so ill be glad of any help .while to object is rotating in a circle ,the object must move in the direction of the head on the pres of a button.thanks in advance.

iam using this script

static var speed : int =5 ;

function Update () {

     if (Input.GetKey (KeyCode.UpArrow)) transform.Translate (Vector3(0,1,0) * Time.deltaTime*speed);
     if (Input.GetKey (KeyCode.DownArrow)) transform.Translate (Vector3(0,-1,0) * Time.deltaTime*speed);
     if (Input.GetKey (KeyCode.LeftArrow)) transform.Translate (Vector3(-1,0,0) * Time.deltaTime*speed);
     if (Input.GetKey (KeyCode.RightArrow)) transform.Translate (Vector3(1,0,0) * Time.deltaTime*speed);
 }

 
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by malekbakeer · Aug 17, 2014 at 11:56 AM

 static var speed : int = 5;
         
 function Update () 
 {
 if (Input.GetKey (KeyCode.UpArrow))
     transform.position.y = Mathf.Lerp (transform.position.y, transform.position.y + 1, Time.deltaTime * speed);
 if (Input.GetKey (KeyCode.DownArrow))
     transform.position.y = Mathf.Lerp (transform.position.y, transform.position.y - 1, Time.deltaTime * speed);
 if (Input.GetKey (KeyCode.LeftArrow))
     transform.position.x = Mathf.Lerp (transform.position.x, transform.position.x + 1, Time.deltaTime * speed);
 if (Input.GetKey (KeyCode.RightArrow))
     transform.position.x = Mathf.Lerp (transform.position.x, transform.position.x - 1, Time.deltaTime * speed);
 }

if you are pressing a button and it does the reverse... try reversing the "-" and "+" marks one at a time

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 mihir solanki · Aug 17, 2014 at 01:34 PM 0
Share

no i just want the object to move in one dirction and not like a third person controller . it is actually rotating in a circle and i want to make it move tangentially when when you press the botton.(imagine flying a kite)

avatar image
0

Answer by itsharshdeep · Aug 17, 2014 at 03:09 PM

`Use inbuilt "Horizontal" & " vertical" axis

With

 Float inputX= Input. GetAxis ("Horizontal");
 Float inputZ = input.GetAxis (" Vertical");
 
 Vector 3 direction = new Vector 3 ( inputX*speed* time.deltaTime, 0, inputZ*speed*Time. deltaatime)
 Transfotm translate(direction);


There might be some errors or mistakes in this . So must google it once

Comment
Add comment · Show 3 · 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 mihir solanki · Aug 18, 2014 at 05:06 AM 0
Share

no i just want the object to move in one direction and not like a third person controller . it is actually rotating in a circle and i want to make it move tangentially when you press the button.(imagine flying a kite). but ill try it.

avatar image itsharshdeep · Aug 18, 2014 at 02:33 PM 0
Share

can u provide any screen shot of ur game/ or scene view

i think the method i told u, will work ..pls provide some more data

avatar image mihir solanki · Aug 19, 2014 at 07:06 AM 0
Share

ok so i basically want it to move it only the direction it is pointing,i.e,making the pointing object move in the pointed direction(up,down,right or left).like in the screenshotsalt text

screenshot_1.png (81.3 kB)
screenshot_2.png (62.2 kB)

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 change the angle my character falls at 1 Answer

Rotating Player 0 Answers

2d Movement Messes up when cube is rotatated 0 Answers

How to make an object go the direction it is facing? 6 Answers

Move the object down while it rotates 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