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 Jake33011 · May 02, 2018 at 02:32 PM · movementpositionissue

The position of my player always returns to (0, 0, 0)

Hey guys I’m having an issue with Unity. I already looked for an answer from someone else who may have had the same issue but I couldn’t find one. So basically here is what happens : I wrote a script to make my ball (Player) move always up and go on one side or the other using the left and right keys on the computer and it works perfectly fine but the problem is that I want my ball to have an original position of something like (-1.3, 0, 0) but when I hit play the ball returns to 0 on the x axis while going up and I can’t figure out why. I had kind of the same problem for my camera-following-player script but then I could resolve it just by setting the transform.position.x to 0, and can’t do that for player otherwise it won’t go right or left anymore. By the way there is no animation on the ball and I just have a character controller in addition to the script on the player. So please if anyone knows how to resolve that problem it would be great thanks :)

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 Kciwsolb · May 02, 2018 at 02:40 PM 0
Share

If you don't post the script you wrote, it is unlikely anyone can help you fix it. :p

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by megabrobro · May 02, 2018 at 02:46 PM

somewhere in your code/project you must be reassigning the value for position to Vector3.zero (0,0,0), after the point where you have set it to -1.3 on x (or at very least the x value is being set back to zero). Without seeing code its hard to help, but maybe you can make a variable of type Vector3 called 'startPosition' and when your player is instantiated be sure to set it to that position after the players been instantiated

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 tormentoarmagedoom · May 02, 2018 at 02:58 PM

Good day.

We need more information to help you. post the code, the inspector screenshot.. something. How you initiate the game? the ball is always theer? or is instantiated?

IS clear the code is making the ball to be in that position, why dont just change its position once started?

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 Jake33011 · May 02, 2018 at 03:42 PM

Alright I’ll post the code in a few hours when I get back home thanks

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 Jake33011 · May 02, 2018 at 04:28 PM

```cs using UnityEngine; using System.Collections; using System.Collections.Generic; using System;

public class PlayerController : MonoBehaviour { private const float TUBE_DISTANCE = 1.5f; // TO CHANGE !

 private CharacterController controller;
 private float verticalVelocity;
 private float speed = 2.0f;
 private int desiredTube = 1; // 0 = Left, 1 = Middle, 2 = Right

 private void Start()
 {
     controller = GetComponent<CharacterController>();
 }

 // Update is called once per frame
 private void Update()
 {
     // Gather the inputs in which tube we should be
     if (Input.GetKeyDown(KeyCode.LeftArrow))
         MoveTube(false);
     if (Input.GetKeyDown(KeyCode.RightArrow))
         MoveTube(true);

     // Calculate where we should be in the future
     Vector3 targetPosition = transform.position.y * Vector3.up;
     if (desiredTube == 0)
         targetPosition += Vector3.left * TUBE_DISTANCE;
     else if (desiredTube == 2)
         targetPosition += Vector3.right * TUBE_DISTANCE;

     // Let's calculate our move delta
     Vector3 moveVector = Vector3.zero;
     moveVector.x = (targetPosition - transform.position).normalized.x * speed;
     moveVector.y = speed;

     // Move the ball
     controller.Move(moveVector * Time.deltaTime);

 }

 private void MoveTube(bool goingRight)
 {
     desiredTube += (goingRight) ? 1 : -1;
     desiredTube = Mathf.Clamp(desiredTube, 0, 2);
 }

} ```

So this is the script on my player

```cs using UnityEngine; using System.Collections; using System.Collections.Generic; using System;

public class CameraMotor : MonoBehaviour { public Transform lookAt; // Our ball // object we're looking at public Vector3 offset = new Vector3(0, 1.29f, -34);

 private void Start()
 {
     transform.position = lookAt.position + offset;
 }

 private void LateUpdate()
 {
     Vector3 desiredPosition = lookAt.position + offset;
     desiredPosition.x = 0;
     transform.position = Vector3.Lerp(transform.position, desiredPosition, Time.deltaTime);
 }

} ```

And this the script on the camera following the player

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 Jeppahx · May 04, 2018 at 07:45 AM 0
Share

As far as I can tell, your Lerp in the player script is not working correctly. You should check this out.

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

135 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

Related Questions

Networked position interpolation implementation (not Dead Reckoning)? 1 Answer

Help!How to validate the client position in headless unity? 0 Answers

how to make an object move like the one it is in contact(moving using Animator) with in unity? 1 Answer

Ignoring the transform.y position on movement 2 Answers

Problem with a motion script 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