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 Hypnix · Jul 14, 2020 at 10:49 AM · animationaiming

My character not rotate her aim while walking and jumping (I have video)

Hello I'm a just an Artist who wan to make a game by my self, so I learning c# I just follow some tutorial and try to mix their coding. I still a noob in coding. I want to make my character (Main body) can move and jump around while her arm(gun) can rotate and point at the player's mouse position. it's work fine when she stand still... But the problem is her arm(gun) not rotate when she walking or jumping.

I want her can enable to rotate and fire, whenever she jump or walk. please help me. thank you very much. Here is a video of the problem: 2 mb https://vimeo.com/user119508875/review/437895619/4e598ce9ce

Here is the code Player Movement using System.Collections; using System.Collections.Generic; using TMPro; using UnityEditor; using UnityEngine;

 public class PlayerMovement : MonoBehaviour
 {
     [SerializeField] private LayerMask platformsLayerMask;
     //private Player_Base playerBase;
 
     public Rigidbody2D rigidbody2d;
     private CapsuleCollider2D capsuleCollider2d;
     
 
     //walk (var)
     float moveInput;
     public float moveSpeed = 17;
     //Jump (Var)
     public float jumpVelocity = 15f;
     private float jumpTimecounter;
     public float jumpTime = 0.25f;
     private bool isJumping;
     
 
 
     private void Awake()
     {
         //playerBase = gameObject.GetComponent<Player_Base>();
         rigidbody2d = transform.GetComponent<Rigidbody2D>();
         capsuleCollider2d = transform.GetComponent<CapsuleCollider2D>();
         
     }
 
 
     private void Update()
     {
         
         //Move Left-Right
         moveInput = Input.GetAxis("Horizontal");
         
         //Jump
         if (IsGrounded() && Input.GetKeyDown(KeyCode.Space))
         {
             
             isJumping = true;
             jumpTimecounter = jumpTime;
             rigidbody2d.velocity = Vector2.up * jumpVelocity;
 
         }
         if (Input.GetKey(KeyCode.Space))//more jump
         {
             if (jumpTimecounter > 0 && isJumping == true)
             {
                 rigidbody2d.velocity = Vector2.up * jumpVelocity;
                 jumpTimecounter -= Time.deltaTime;
             }
             else
             {
                 isJumping = false;
             }
 
         }
 
         if (Input.GetKeyUp(KeyCode.Space))
         {
             isJumping = false;
         }
 
 
     }
 
     private void FixedUpdate()
     {
         //Debug.Log(rigidbody2d.velocity);
 
         //walk
         rigidbody2d.velocity = new Vector2(moveInput * moveSpeed, rigidbody2d.velocity.y);
         
         
     }
 
     //ground checker
     private bool IsGrounded()
     {
         RaycastHit2D raycastHit2d = Physics2D.BoxCast(capsuleCollider2d.bounds.center, capsuleCollider2d.bounds.size, 0f, Vector2.down, 0.1f, platformsLayerMask);
         //Debug.Log(raycastHit2d.collider);
         return raycastHit2d.collider != null;
 
     }
 
 }
 

And here is the code for aiming her weapon

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerAim : MonoBehaviour
 {
     //Aim
     public Camera cam;
     private Vector2 mousePos;
     public Rigidbody2D rigidbody2d;
     
 
     void Update()
     {
         HandAim();
         Shooting();
 
     }
     private void HandAim() //Aim
     {
         
         mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
         Vector2 lookDir = mousePos - rigidbody2d.position;
         float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg;
         rigidbody2d.rotation = angle;
     }
     
     private void Shooting()   //Shoot
     {
         if (Input.GetMouseButtonDown(0))  //0 = left click
         {
 
         }
     }
   
 }
 

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 Fedor4ka · Nov 02, 2021 at 04:13 AM 0
Share

Well, @Hypnix did you find the mistake? I have a sme problem and i dont know how to correct it

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.

Follow this Question

Answers Answers and Comments

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

Can the animation editor create local rotational data? 3 Answers

Adding animation clips via script 2 Answers

How to make hand weapon IK collision/retraction with obstacles like walls, cover etc. like RE2 Remake? 0 Answers

Fighting Game - Aiming attack animation at mouse cursor? 1 Answer

How to get a animation to play without changing the pozition the gun is in when aming down sights 0 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