• 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 biedaczeek · Feb 25, 2020 at 09:17 PM · unity 2dsprite renderer

Unity 2D fliping player with position of mouse,Unity 2D fliping player with mouse

Hello! I'm begginer so please help me with adding to my code, code that i need. I want make something like on video. Player is looking at mouse but it doesn't move in 360 just left and right like on this video https://www.youtube.com/watch?v=AiJfHTdw9DQ&list=LLexq7PpIet4CgVMU7iNwdFA∈dex=2&t=188s

Also I'm leaving here my movement code:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class playermovment : MonoBehaviour {

 public float moveSpeed = 5f;

 public Rigidbody2D rb;

 Vector2 movement;

 // Update is called once per frame
 void Update()
 {
     movement.x = Input.GetAxisRaw("Horizontal");
     movement.y = Input.GetAxisRaw("Vertical");
 }

 void FixedUpdate()
 {
     rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
 }

} ,I'm beginner so can u help me with adding to my code this code that i need. I want make something like on this video that character facing at mouse.

https://www.youtube.com/watch?v=AiJfHTdw9DQ&list=LLexq7PpIet4CgVMU7iNwdFA∈dex=2&t=188s

Also here is my code:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class playermovment : MonoBehaviour {

 public float moveSpeed = 5f;

 public Rigidbody2D rb;

 Vector2 movement;

 // Update is called once per frame
 void Update()
 {
     movement.x = Input.GetAxisRaw("Horizontal");
     movement.y = Input.GetAxisRaw("Vertical");
 }

 void FixedUpdate()
 {
     rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
 }

}

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

0 Replies

· Add your reply
  • Sort: 

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

127 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 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 problem with displaying sprites in final build game 1 Answer

Sprite renderer lit by light 1 Answer

Can I get a sprite from a sprite sheet? 1 Answer

Sprite atlas creation option has all but disappeared! 1 Answer

Drawing sprites in front of meshes 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges