Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 LukeMildenberger · Jan 10, 2020 at 07:26 AM · 2dmovementshooterjittery

Jittery Movement (2D)

Yeah, so basically I'm making a 2D Sideview shooter game similar to Gradius or Cuphead (Plane levels) and no matter what I do I'm getting jittery and weird looking movement for both my witch MC and enemies. I've looked through other unity answers and have found people with similar problems but none of them are exactly the same and none of the solutions have worked so far. There are no physics and the camera is always completely stationary.

Enemy Movement Script

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class EnemyMovement : MonoBehaviour
 {
     public GameObject Enemy;
     public float Movespeed = 15f;
     
     // Start is called before the first frame update
     void Start()
     {
         
     }
 
     // Update is called once per frame
     void FixedUpdate()
     {
         Enemy.transform.position = new Vector2(
            transform.position.x + (Movespeed * Time.deltaTime),
            transform.position.y
            );
     }
 }
 

Character Movement Script

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class Movement : MonoBehaviour
 {
     public Joystick Joystick;
     public GameObject Witch;
     public float Speed = 10f;
     public Button FireButton;
     public GameObject MagicSP;
     public GameObject MagicBullet;
 
     // Start is called before the first frame update
     void Start()
     {
         FireButton.onClick.AddListener(TaskOnClick);
     }
 
     // Update is called once per frame
     void Update()
     {
 
         //Movement
 
         Vector2 pos = transform.position;
 
         //Veritcal
 
         pos.y += Joystick.Vertical * Speed * Time.deltaTime;
 
         transform.position = pos;
 
         //Horizontal
         pos.x += Joystick.Horizontal * Speed * Time.deltaTime;
 
         transform.position = pos;
 
     }
 
     void TaskOnClick()
     {
         Instantiate(MagicBullet, MagicSP.transform.position, MagicSP.transform.rotation);
     }
 }
 

I'm kind of a noob to this so sorry if its a stupid question but I'd appreciate any and all advice. Thanks! :)

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by rufopufo · Jan 10, 2020 at 09:22 AM

Hi there,

Probably you are getting that weird movement because you are changing directly x and y components.

It may help you if you use Translate() method, as following: Enemy.transform.Translate(Movespeed*Time.deltaTime,0,0);

And do the same for the Player. This Translate method just moves along the x, y or z axis, as much units as you set there.

Btw, I personally prefer to generate the player movement with the Rigidbody component, instead of using the transform component. But I don't really know even if you are using rigidbodies... So I answered the question using the transform component, as you had in your code.

Hope it helps.

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 LukeMildenberger · Jan 14, 2020 at 02:29 AM

Hi rufopufo, thanks so much for the answer! Unfortunately I'm still getting the jittery movement. I'm starting to think that it might not be the scripts but instead a setting with Unity or my hardware. My first thought was that it might be the refresh rate of my monitor, but then I tried it with another monitor and then a TV and I still got the same results. I also tweaked the fixed timestep setting in Unity because I saw something about it in another Unity Answers post, but the problem persisted. any advice would be helpful, thanks! :)

Here is a video if it helps: Youtube Video

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 Marioooo · Jan 14, 2020 at 06:32 AM

If there's no physics involved so you made your own physics system.

There's a platformer tutorial in unity which involves creating your own physics system... Take a look at it... Also I don't see your physics system so how do you check wherever you're hitting something? Maybe that jittery movement us caused by moving the object and then calculating physics about where's ground.

Use a raycast or a collider casting to see if the gravity must be applied or not...

Hope it helps

Comment
Add comment · Show 7 · 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 LukeMildenberger · Jan 14, 2020 at 03:10 PM 0
Share

Hi $$anonymous$$arioooo Thanks for your answer! The reason why I don't have a physics system is because there is no gravity or ground . In my game you play as a witch on a broom flying through the air, which is why I didn't add any physics. Think of the game play like Gradius or the plane levels in Cuphead. Thanks for any advice!

avatar image Marioooo LukeMildenberger · Jan 14, 2020 at 05:12 PM 0
Share

In that case you can still use RIGIDBODY 2D. Just set gravity scale 0, set a drag, freeze rotation and use Rigidbody2D.AddForce(vector2D, Force$$anonymous$$ode.Impulse) To move anywhere you want and after adding the force, clamp velocity to $$anonymous$$ax movement speed. It'll be smoother and easier.

avatar image LukeMildenberger Marioooo · Jan 15, 2020 at 01:00 AM 0
Share

Thanks again for the reply marioooo! I did what you said and it helped a lot! unfortunately there is still a sort of vibration/jittery movement with the enemies. I honestly have no idea what to do, I've tried so much but to no avail. if you have any other ideas I would love to hear them. Thanks :)

Show more comments
avatar image
0

Answer by ArKeid0s · Jun 18, 2021 at 07:35 AM

Did you manage to fix your problem ? I have the same problem

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

280 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

Related Questions

How can i add simple back and forth movement on the Y-axis to an enemy that has velocity on the X-axis attached to it? 3 Answers

How to get a character to slowly move onto screen 1 Answer

How to keep the last good position when interacting with triggers? 1 Answer

I need to change the animation when my speed increases in a 2D game 0 Answers

Damaging Enemies 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