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 deamo · Mar 21, 2014 at 03:53 PM · positionplayermousefollowface

Make game object face player and at the same time follow mouse position

Hi!

I'm making this 2d platform game. The player is playing the game with help by rigidbody2d. There is no actual control over the player character. He is moving down the levels with help of colliders and rigidbody2d. So he is bouncing his way downwards.

I have an game idea to implement lifelines that the one who plays the game can use to rescue the player from death. But for one of my ideas I need a game object to follow mousepointer and always have a special side of the lifeline to face the player. Looks something like this at the moment:

http://i.imgur.com/NG6CdSa.png

So, I first tried to find a way to make the lifeline to follow the mouse position. But I only found examples for 3D games.

And second I though that the upper side of the marked object that have a thin blue line should always face the player so I will be able to rescue my player from different threats. Like big falls and such.

I failed on both these tasks :(

Hope that someone understand what I need and can help out! :)

Comment
Add comment · Show 1
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 deamo · Mar 21, 2014 at 10:11 AM 0
Share

Another thing. The moveable game object should not collide with game level elements, but should "collide" with the player so I can use it to rescue him with it, but not get stuck in game level elements.

2 Replies

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

Answer by robertbu · Mar 21, 2014 at 04:29 PM

Your camera will be a certain distance from the playing plane. Say that that distance is 10. You can position a world game object at the cursor (both orthographic and perspective cameras) with:

 var pos = Input.mousePosition;
 pos.z = 10;
 transform.position = Camera.main.ScreenToWorldPoint(pos);

You can get the object to face another object by:

 var dir = player.position - transform.position;
 angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
 transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

Note the above code assumes the 'forward' of your sprite is on the right.

As for 'collide', you can use a trigger, or you can calculate a distance from the player, or you can use any of the Physics2D functions like OverlapPoint().

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
avatar image
0

Answer by nazia08 · Mar 26, 2014 at 10:54 AM

The Game Maker game development suite from YoYo Games contains a wide variety of drag and drop functions for fast game design...

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

Camera rotation around player while following. 6 Answers

Rotate the player to face where the mouse is pointing 3 Answers

Camera Rotate to mouse position -2 Answers

Rotate to face player, drunk issues 0 Answers

Following mouse 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