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
1
Question by Razputin · Feb 17, 2014 at 04:41 PM · movementplayerturn-based

Moving player 1 unit from current position.

I'm just trying to get my player model to move 1 unit, the direction doesnt matter but in the end i'll want to be able to move up one down one left one and right one. But I also want there to be a limited number of moves you can make before ending the players turn and resetting the number the player can move.

Biggest problem i'm having is that I don't know how to call the players current position.

 using UnityEngine;
 using System.Collections;
 
 public class PlayerMovement : MonoBehaviour {
 
     Vector3 playerPosition;
     public int playerCanMove = 1;
 
     void Start () {
         playerPosition = transform.position;
         for ( playerCanMove = 1; playerCanMove >= 1; playerCanMove-- )
         {
                 if(Input.GetButtonDown("Vertical"))
                 {
                 playerPosition = (new Vector3(transform.position.x,transform.position.y + 1, -1));
                 }
             }       
         }
     }

If someone could explain to me how to do this i'd be very thankful.

This is in 2d so I have the z axis at -1 to bring the player to the foreground.

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
2
Best Answer

Answer by GameVortex · Feb 17, 2014 at 06:34 PM

You can easily use **Transform.Translate** to move an object:

 //moves object 1 unity to the right
 transform.Translate(1.0f, 0.0f, 0.0f);

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 Razputin · Feb 18, 2014 at 03:15 AM 0
Share

Thank you, didn't realize it was this simple.

avatar image ccx217 · Sep 26, 2015 at 06:47 PM 0
Share

how would you make that a smooth transition?

avatar image RuneShiStorm · Oct 08, 2019 at 11:57 PM 0
Share

omg, thats exaclt what I was looking for. any idea how to make the transform more smooth? (with your line of code the player is simply "teleporting" to the new spot...) this is fine, but it would be cool if it was a "smoooooth" transecation.

avatar image
0

Answer by whydoidoit · Feb 17, 2014 at 06:43 PM

Vertical is an axis you get with GetAxis and has a value between -1 and 1 with 0 being at rest. If you want to do this on a button use KeyCode.X (or any other key you like).

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

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

22 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

Related Questions

Player is Speeding up in collisions 0 Answers

All Unity Engine games' controls not working 1 Answer

How to limit the forces applied to an object to just forward, left, and right? 0 Answers

Do something every each multiple of 1000.. 2 Answers

Character getting stuck on curbs.. 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