• 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 matthew77 · Aug 29, 2017 at 04:12 AM · positioning

Click on an object to sit

Hi. I'm trying to make it so if I click on an object ,like say a chair, that it will change the character's position and rotation and seat the player in it.

I think I can manage to trigger the animation once the player is in the correct position. My problem is how to click the object and have the player move to that position and rotation. Can anyone help me out , or maybe let me know what kind of tutorials I should be looking for to achieve this?

Thanks in advance.

Comment
Add comment · Show 2
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 matthew77 · Aug 29, 2017 at 04:16 AM 0
Share

Edit: I don't necessarily need the player to walk over smoothly to the object , something that brings/teleports the character to that position/rotation would work fine for me.

avatar image Umresh · Aug 29, 2017 at 05:22 AM 1
Share

For Clicking you can use Physics.Raycast and using raycast you can get gameobject, you'll have transform of the clicked object use it.

  if ( Input.Get$$anonymous$$ouseButtonDown (0)){ 
    RaycastHit hit; 
    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); 
    if ( Physics.Raycast (ray,out hit,100.0f)) {
      Debug.Log("You clicked " + hit.transform.name); // Clicked object
    }
  }

1 Reply

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

Answer by Paricus · Aug 29, 2017 at 09:25 AM

     public Transform animationPos;
     public Animator anim;
     public Transform player;
 
     private void OnTriggerStay(Collider other)
     {
         if (Input.GetMouseButtonDown(0))
         {
             player.position = animationPos.position;
             player.rotation = animationPos.rotation;
 
             anim.SetTrigger("your animation trigger name");
         }
     }

Add the script to your chair Create an empty game object (animationPos) and set its position and rotation to values that work with your sitting animation.
set up a trigger that encompasses the chair Reference your players animator and trigger the sitting animation when the mouse is clicked

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 Paricus · Aug 29, 2017 at 09:27 AM 0
Share

https://www.youtube.com/watch?v=7JEoG4xubP8&ab_channel=Holistic3d

a more complex approach to triggering a sitting animation

avatar image matthew77 · Aug 31, 2017 at 12:40 AM 0
Share

Thank you so much that was exactly what I needed!

One more thing though can you point me toward a tutorial on triggering the animation? I thought it would be easier to find but I've been looking and looking and can't find anything on it.

avatar image Paricus · Aug 31, 2017 at 06:36 AM 0
Share

https://youtu.be/s7EIp-OqVyk

https://unity3d.com/learn/tutorials

The second link has everything you could possibly need to know about the basics of unitys functionality.
I also highly recommend checking out the unity live training archive and example projects (like s$$anonymous$$lth and survival shooter) as they cover a lot of common functionality seen in games.

Hope this helps :)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

69 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 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 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

Unity 2D physics working differently in unity as per platform 1 Answer

How to change position of a Gameobject according to Quaternion data of another Object without converting it to Euler data ?, 0 Answers

Smooth continuous movement with fast updating position 0 Answers

Issue with sprite / animation postion on preview normal on edit mode 1 Answer

How to align GameObjects based on their corner not the center point 3 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