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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

How to increment value of axis when something happens

Discussion in 'Scripting' started by phantom_x404, Aug 13, 2020.

  1. phantom_x404

    phantom_x404

    Joined:
    Apr 26, 2020
    Posts:
    26
    I have a player and I want something to spawn beneath the player, but the spawned items will stack up beneath it, in order to not mess up the physics system due to the object spawning inside the player, I make the player jump using jumpforce, but this sometimes messes up the system and the objects merge with each other only to separate with a large amount of force causing player to fly away. Now I want to make it such that whenever the Mouse is clicked or the screen is tapped, the players position automatically increases and then an object spawn beneath it. So lets say the object is of X height. Now I want the player to move up by X whenever the screen is tapped and then the object must spawn below it.
    However as you know, we can not add float values to the axis, I realized it the hard way by doing:
    Code (CSharp):
    1. player.transform.position = (player.transform.position + (0, 10, 0));
    So is there a way to accomplish this? I've searched some forums but haven't gotten the desired results and have been stuck with this issue for a while(More than a Week). It would be awesome if anyone could help me out or just guide me in the right direction :)
     
  2. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    your syntax is wrong, you have to do

    Code (CSharp):
    1. player.transform.position = (player.transform.position + new vector3(0, 10, 0));
     
    phantom_x404 likes this.
  3. phantom_x404

    phantom_x404

    Joined:
    Apr 26, 2020
    Posts:
    26
    Than
    k you very much, it was a very dumb mistake