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 euanross400 · Jul 14, 2021 at 02:25 PM · rigidbody2dlookatmouse

Child object won't follow the player.

I am making a top down isometric game and I used a used a tutorial for top down shooting. It's this one: https://www.youtube.com/watch?v=LNLVOjbrQj4 In it he makes the player face the mouse but for my game I didn't want my player to face the mouse which resulted in it not firing at the mouse. So I applied the code to the empty game object "FirePoint" which is a child of the player but when a child has a rigidbody2D it doesn't follow the player but the aiming works. So if anyone knows how to get it to follow the player or a better method for shooting with mouse aim without rotating the player please leave a comment.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class LookAtMouse : MonoBehaviour
 {
     // Fix this. FirePoint won't move with the player even though it's a child object of the player
 
     public Rigidbody2D rb;
     public Camera cam;
 
     Vector2 mousePos;
 
     //public Transform Parent;//Remember to assign the parent transform 
     //private Vector3 pos, fw, up;
 
     // Start is called before the first frame update
     void Start()
     {
         //pos = Parent.transform.InverseTransformPoint(transform.position);
         //fw = Parent.transform.InverseTransformDirection(transform.forward);
         //up = Parent.transform.InverseTransformDirection(transform.up);
     }
 
     // Update is called once per frame
     void Update()
     {
         mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
 
         //var newpos = Parent.transform.TransformPoint(pos);
         //var newfw = Parent.transform.TransformDirection(fw);
         //var newup = Parent.transform.TransformDirection(up);
     }
 
     private void FixedUpdate()
     {
         Vector2 lookDir = mousePos - rb.position;
         float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg - 90f;
         rb.rotation = angle;
     }
 }
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 IvanBgd · Jul 14, 2021 at 07:18 PM 1
Share

check if its static (in the inspector window), it should be off.

avatar image euanross400 IvanBgd · Jul 14, 2021 at 09:11 PM 0
Share

It's dynamic

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by euanross400 · Jul 14, 2021 at 09:12 PM

Wait I fixed it by putting it on kinematic

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

125 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

Related Questions

Problem with a RigidBody and IsKinematic... I think 1 Answer

My flipped character ragdoll has wrong hingejoint anchor positions 0 Answers

Rigidbody2D.IsKinematic giving object reference not set? 0 Answers

Drag to add power, release to throw at opposite angle (RigidBody2D), strange beahviour. 3 Answers

2DColliders going through eachother 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