Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 ILLUSION2006 · Aug 02, 2020 at 04:51 AM · 2d-platformer2d-physics2d sprites2d-gameplay2dmovement

How To Make Game Remember User Input Then Play It Out, But Backwards

Ok so i made a game where once a person has made enough arrow key presses (still have to code that part) the should remember which keys were pressed and play them out when a certain condition is filled. However the keys should be played backwards. Ex. If I press up arrow down arrow right arrow; the game should play right arrow, down arrow, up arrow.

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
0
Best Answer

Answer by ILLUSION2006 · Aug 05, 2020 at 06:09 PM

Okay everyone I solved my problem, all I did was incorporated a timer and then at certain times started and ended the rewinds. Instead of disabling the movement, I figured out the rewind script was actually not allowing movement while playing, the only reason it looked like that, is because it would still allow the character to flip which way they were facing. To fix this I simply made a mother sprite(which btw looks the same even if it is mirrored) and just used it whenever I needed to rewind.

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
1

Answer by dorusoftware · Aug 02, 2020 at 09:49 PM

this shows the behavior you describe

https://www.youtube.com/watch?v=UoNumkMTx-U

Comment
Add comment · Show 1 · 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 ILLUSION2006 · Aug 03, 2020 at 01:50 AM 0
Share

Hey everyone so I watched a brackeys tutorial and its extatly what I wanted...... my only problem is that instead of the rewind only happening when the player presses enter, I need it to happen after... like 20 steps. BTW the game needs to do that automatically - Here are the 2 scripts that I need to modify.

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

public class CommandHandler : $$anonymous$$onoBehaviour {

 public bool isRewinding = false;

 List<PointInTime> pointsInTime;

 Rigidbody2D rb;

   
 // Start is called before the first frame update
 void Start()
 {
     pointsInTime = new List<PointInTime>();
     rb = GetComponent<Rigidbody2D>();
 }

 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Return))
         StartRewind();

     if (Input.GetKeyUp(KeyCode.Return))
         StopRewind();
 }

 private void FixedUpdate()
 {
     if (isRewinding)
         Rewind();
     else
         Record();
 }


 void Rewind()
 {

     if(pointsInTime.Count > 0)
     {
         PointInTime pointInTime = pointsInTime[0];
         transform.position = pointInTime.position;
         transform.rotation = pointInTime.rotation;
         pointsInTime.RemoveAt(0);
     }
     else
     {
         StopRewind();
     }
    
 }

 void Record()
 {
     pointsInTime.Insert(0, new PointInTime(transform.position, transform.rotation));
 }


 public  void StartRewind()
 {
     isRewinding = true;
     rb.isKinematic = true;
 }


 public void StopRewind()
 {
     isRewinding = false;
     rb.isKinematic = false;
 }

}

THIS IS THE OTHER ONE -

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

public class PointInTime { public Vector3 position; public Quaternion rotation;

 public PointInTime (Vector3 _position, Quaternion _rotation)
 {
     position = _position;
     rotation = _rotation;

 }

}

While I am pretty sure that only the first one needs to be edited, I posted the second incase it helps.

avatar image
0

Answer by PlayCreatively · Aug 02, 2020 at 02:25 PM

     const int maxStepCount = 5;
     Vector2[] stepRecord = new Vector2[maxStepCount];
     int stepCount;
 
     void AddStep(Vector2 dir)
     {
         stepRecord[stepCount++] = dir;
     }
 
     private void Update()
     {
         if (keyPressed)
             AddStep(inputDir);
 
         if(stepCount >= maxStepCount-1)
         {
             for (int i = stepRecord.Length - 1; i >= 0; i--)
                 This is the sequence in reverse => stepRecord[i];
         }

You can work from here. Hope it helps.

Comment
Add comment · Show 1 · 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 ILLUSION2006 · Aug 02, 2020 at 06:13 PM 0
Share

Hi Im really new to this so could u explain what is going on here? I will attach my movement script if that helps (btw it is blackthornprods platformer movement script)

using UnityEngine;

public class $$anonymous$$ovement : $$anonymous$$onoBehaviour { public float speed; public float jumpForce; private float moveInput;

 private Rigidbody2D rb;

 private bool facingRight = true;

 private bool isGrounded;
 public Transform groundCheck;
 public float checkRadius;
 public Layer$$anonymous$$ask WhatIsGround;


 private int extraJumps;
 public int extraJumpsValue;

 void Start()
 {
     extraJumps = extraJumpsValue;
     rb = GetComponent<Rigidbody2D>();
 }

 void FixedUpdate() // We did "FixedUpdate" because we are dealing wth physics
 {
     isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, WhatIsGround);


     moveInput = Input.GetAxis("Horizontal");
     Debug.Log(moveInput);
     rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);

     if (facingRight == false && moveInput > 0)
     {
         Flip();
     }
     else if (facingRight == true && moveInput < 0)
     {
         Flip();
     }
 }

 void Update()
 {
     if (isGrounded == true)
     {
         extraJumps = extraJumpsValue;
     }

     if (Input.GetKeyDown(KeyCode.UpArrow) && extraJumps > 0)
     {
         rb.velocity = Vector2.up * jumpForce;
         extraJumps--;
     }


  

     else if (Input.GetKeyDown(KeyCode.UpArrow) && extraJumps == 0 && isGrounded == true)
     {
         rb.velocity = Vector2.up * jumpForce;
     }

 }

 void Flip()
 {
     facingRight = !facingRight;
     Vector3 Scaler = transform.localScale;
     Scaler.x *= -1;
     transform.localScale = Scaler;
 }

}

avatar image
0

Answer by ILLUSION2006 · Aug 04, 2020 at 09:06 PM

Hi I have got my rewind script working. Theres only one issue. In my rewind script I disable my movement script then re enable it after the rewind is done. My only issue is that after completing the rewind, my player character is able to move but for some reason not jump. Here is my movement script -

using UnityEngine;

public class Movement : MonoBehaviour { public float speed; public float jumpForce; private float moveInput;

 private Rigidbody2D rb;

 private bool facingRight = true;

 private bool isGrounded;
 public Transform groundCheck;
 public float checkRadius;
 public LayerMask WhatIsGround;


 private int extraJumps;
 public int extraJumpsValue;

 void Start()
 {
     extraJumps = extraJumpsValue;
     rb = GetComponent<Rigidbody2D>();
 }

 void FixedUpdate() // We did "FixedUpdate" because we are dealing wth physics
 {
     isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, WhatIsGround);


     moveInput = Input.GetAxis("Horizontal");
     Debug.Log(moveInput);
     rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);

     if (facingRight == false && moveInput > 0)
     {
         Flip();
     }
     else if (facingRight == true && moveInput < 0)
     {
         Flip();
     }
 }

 void Update()
 {
     if (isGrounded == true)
     {
         extraJumps = extraJumpsValue;
     }

     if (Input.GetKeyDown(KeyCode.UpArrow) && extraJumps > 0)
     {
         rb.velocity = Vector2.up * jumpForce;
         extraJumps--;
     }


  

     else if (Input.GetKeyDown(KeyCode.UpArrow) && extraJumps == 0 && isGrounded == true)
     {
         rb.velocity = Vector2.up * jumpForce;
     }

 }

 void Flip()
 {
     facingRight = !facingRight;
     Vector3 Scaler = transform.localScale;
     Scaler.x *= -1;
     transform.localScale = Scaler;
 }

}

AND HERE IS MY REWIND SCRIPT #1 -

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

public class CommandHandler : MonoBehaviour {

 public bool isRewinding = false;

 List<PointInTime> pointsInTime;

 Rigidbody2D rb;

 //for Timer

 private float secondsCount;
 private int minuteCount;


 // For s






 // Start is called before the first frame update
 void Start()
 {
     pointsInTime = new List<PointInTime>();
     rb = GetComponent<Rigidbody2D>();


 }

 // Update is called once per frame
 void Update()
 {
     UpdateTimerUI();// for timer


     if (secondsCount > 10)
     {
         StartRewind();
         Debug.Log("10 second rewind begins");
         
     }


     if(secondsCount > 18)
     {
         StopRewind();
         Debug.Log("10 second rewind ended");
        
     }




     if (secondsCount > 30)
     {
         StartRewind();
         Debug.Log("30 second rewind begins");
        
     }



     if (secondsCount > 35)
     {
         StopRewind();
         Debug.Log("30 second rewind ended");
        
     }


     if (minuteCount > 1) 
     {
         StartRewind();
         Debug.Log("1 minute rewind begins");
         
     }


     if (minuteCount > 1.2) 
     {
        StopRewind();
         Debug.Log("1 minute rewind ends");
       
     }

And here is rewind script #2 -

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

public class PointInTime { public Vector3 position; public Quaternion rotation;

 public PointInTime (Vector3 _position, Quaternion _rotation)
 {
     position = _position;
     rotation = _rotation;

 }

}

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

150 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

Related Questions

How to create soil or sand?? 1 Answer

How do instantiate a ghost prefab when the player dies? 2 Answers

Player getting stuck between grounds 0 Answers

Destroy a gameObject in the scene if instantiate the same gameObject 0 Answers

2D Z-Levels HELP Needed! Can I script multiple objects to run on z levels,,2d Multiple Z levels in one scene 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