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 $$anonymous$$ · Jul 09, 2012 at 04:15 PM · playervector3coroutinelerpslerp

Moving the player toward a direction

I'm working on a dungeon crawler kind of game(Dungeon Master style) and I'm stuck now at making the player going toward a specific direction.

I'll try to explain what I've done until now, instead of using the method on the wiki about the Grid based movements with Horizontal and Vertical axes, I've been using a raycast method to check for the next tile.

The raycasts cast on all fourth direction only when a gui button is pressed, so I'm not using any input type of control. The raycast check the next tile that have another script with just a bool if is empty or not, and if is empty you can advance.

Now I'm stuck on my coroutine that should run the move for the player, it all checks good and all, but I can't menage to make the player move.

I've been reading that I should use Vector3.Lerp, by using and start and ending position for the movement, for the start position there is no prob I set it just on transform.position, but I have no idea how to calculate the ending position.

Thats my coroutine:

  public IEnumerator MovePlayer (string dir) {
 
  _startPoint = transform.position;
  
  if(!_isMoving){
  _isMoving = true;
  
  if(dir == "forward"){
  Debug.Log ("MOVE FORWARD");
  }
  else if(dir == "backward"){
  Debug.Log ("MOVE BACKWARD");
  }
  else if(dir == "left"){
  Debug.Log ("MOVE LEFT");
  }
  else if(dir == "right"){
  Debug.Log ("MOVE RIGHT"); 
      }
      while (true) {
              yield return null;
          }
  _isMoving = false;
  }
  }

Is nothing fancy, but I don't know how to set up the whole thing to actual move the player, any help would be appreciated.

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

1 Reply

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

Answer by stingman · Jul 09, 2012 at 10:33 PM

Since you are using buttons to determine your player path you need to set your end destination as the location your button recognizes as an empty tile space as that is where your player will move. You need to then define 2 transforms: 1 for that tile and one for your current position. Here is an example... this is untested but it will definately get you in the right direction:

 Transform startPosition;
 Transform tilePosition;
 float moveTime = 1.0 // This will be the time variable that will determine how long it will take your player to move between the 2 transforms
 
 //whatever function you will call to make your character move when clicking a button.  
 void OnGUI(){ 
 transform.position = Vector3.Lerp(startPosition, tilePosition, moveTime * Time.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 $$anonymous$$ · Jul 09, 2012 at 11:22 PM 0
Share

$$anonymous$$any thanks, now it works all good.

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

Moving player in an arc, from startPoint to endPoint 2 Answers

How can I Vector3 Slerp or Lerp locally? 3 Answers

Activating 3 rotations based on multiple presses on one key 2 Answers

How to use Vector3.Lerp without slow-down 3 Answers

How to Gradually Increase Speed with Lerp or Slerp? 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