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 Capricornum · Sep 12, 2017 at 07:00 PM · positionplayergamechangestart

Player GameObject changes position when I start the game

Dear Community, I am another newcomer to Unity3d and C#. I have created a scene in order to grasp the concept of classes and instances. In the scene a player (capsule) stands in front of a bank (lots of cubes) next to his car(another cube). (see here)

alt text

As you can see the Player Controller has a "Character Controller" Component attached and a "Client Controller" Script, which goes like this:

using UnityEngine; using System.Collections;

public class ClientController : MonoBehaviour {

 public float speed = 4.0f;
 public float jumpSpeed = 7.0f;
 public float gravity = 30.0f;
 Vector3 direction = Vector3.zero;
 CharacterController controller;

 void Start ()
 {
     controller = GetComponent<CharacterController> ();
 }
 
 void FixedUpdate () 
 {
     Move ();
 }
     
 void Move () 
 {
     if (controller.isGrounded)
     {
         direction = new Vector3 (Input.GetAxis ("Horizontal"), 0f, Input.GetAxis ("Vertical"));
         direction *= speed;
         if (Input.GetButton ("Jump")) 
         {
             direction.y = jumpSpeed;
         }
     }
     direction.y -= gravity * Time.deltaTime;
     controller.Move(direction*Time.deltaTime);
 }

}

My problem is, that as soon as I switch to Game mode my Player GameObject moves out of the camera view, to a weird position somewhere, where no man has gone before (see here)

alt text I don't know why?? This does not happen if I deactivate the Client Controller Script or my "character Controller" component or both. The error occurred after I altered my "police" prefab, that is instantiated when the player enters the bank not using the door (or metal detector). Can anyone help me? Thank you!

game-view.jpg (303.5 kB)
scene-view.jpg (371.8 kB)
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 Capricornum · Sep 12, 2017 at 09:14 PM

Allright. I figured it out. Actually its quite interesting: Before the error occurred I had added my "police" prefab (a yellow capsule) to the scene. Some minutes before I had changed "police's" mesh to a cube in the Mesh Filter component. (I had originally created it as a capsule), and had removed the capsule collider and added a cube collider. This time I changed the mesh back to a capsule and added another capsule collider (removing the cube collider). To make things tidy i moved the collider component up in the inspector (with that gear menu) upon which I received a message, that this action would break my prefab. I continued, because I assumed it wouldn't be so bad. :) And finally I hit -apply- so that my new "police's" settings in the scene would be applied to my prefab. What actually happened is that my GameObject "Floor" (a plane) had suddenly changed its mesh collider component to a capsule collider component. This in turn kicked my Player Object away from it on game start. - Weird - Thank you everyone.

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 Litleck · Sep 12, 2017 at 08:27 PM

It might be your if statement triggering at the beginning causing it to move, that's all I can think of.

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 Capricornum · Sep 12, 2017 at 08:45 PM 0
Share

Thank you. I'll keep looking.

avatar image
0

Answer by benaiahmack3 · Sep 13, 2017 at 12:11 AM

Might be your if statement.

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 bluebird331 · Oct 18, 2020 at 08:47 AM

I'm having trouble with the codes. Please remove this error code! pls


error-code.png (5.6 kB)
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

115 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

Related Questions

Changing player's moving direction 0 Answers

Change player's y-position for a specific animation 1 Answer

My player returns to default position when pressing play 1 Answer

Model change position to (0,0,0) when I Start the game. 1 Answer

Camera rotation around player while following. 6 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