Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Store position of player at time of button press

Discussion in 'Scripting' started by balooh, May 1, 2022.

  1. balooh

    balooh

    Joined:
    Aug 3, 2020
    Posts:
    2
    Heyo, I am new to C# scripting in Unity and can't for the life of me figure out this (what I assume to be an easy) problem:

    When I hit jump, I want to store the last 'known' position of my character controller in a vector3.

    I thought I could have an
    if(!isjumping){
    storedPosition = player.position}​
    at the beginning of my jump function but that doesn't seem to work. When I press jump and isJumping changes to true, wouldn't 'storedPosition' remain the last value?

    In coding in general: What's the term for stuff like this so I know what to Google for?

    Thank you!
     
  2. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    777
    Hello,

    In these kind of situations it's usually a good idea to put some Debug.Log lines in the code to write whats going on to the console log. For example one in the line after where the storedPosition is supposed to be changed.
    Debug.Log("storedPosition: " + storedPosition);

    This will let you know if the code is running, at all, or maybe more often, as you think.

    https://docs.unity3d.com/ScriptReference/Debug.Log.html
     
    balooh likes this.
  3. balooh

    balooh

    Joined:
    Aug 3, 2020
    Posts:
    2
    Totally not the answer I was looking for but absolutely the thing I needed to do. Thank you kind stranger!