Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 MatheusCroft · Jun 21, 2014 at 06:15 PM · positionplatformx

Different positions in just one scene. 10 x axys != 4 x axys

My first level scene was working fine, but I had to work in the complete game design, so I add more bricks and put my "spike" elsewhere. As the position was changed, my spike wasn't doing what it was supposed to do, obviously. I just needed to set other values and it could work like the spikes from sonic the hedgehog, coming out from a wall and then going back. The positions are not right though. Here is the code:

 using UnityEngine;
 using System.Collections;
 
 public class Espinho : MonoBehaviour {
 
     public Vector3 movimentacao;
     private PausarGame pausarGame;
     public float XMaximo;
     public float XMinimo;
 
     void Start()
     {
         pausarGame = FindObjectOfType (typeof(PausarGame)) as PausarGame;
     }
 
     void Update () {
     
         if (!pausarGame.pause) {
                         transform.position += movimentacao;
                 }
         VaiVolta ();
 
     
     }
 
     void VaiVolta()
     {
         if (transform.position.x >XMaximo) {
             movimentacao*=-1;
                 }
         else if (transform.position.x <XMinimo) {
             movimentacao*=-1;
         }
     }
 
 }

When it is located at -1.651396 x axys and for example I want it to go to 6 x axys, it goes to 0.7 and then change directions. It is the same when it goes back, when I put -1, it goes to -6.2 and then goes back again. It is working fine in other scenes, but in my first level it is kinda changing the values and I don't know what is going on. It is working as it should, but not working with the values I really want it to work. I thought it was because of the prefab or something, but it is happening the same when I just add a new object with the same script and with the fireball, which has almost the same script and has to do the same the spike is supposed to do. Thanks in advance.

Comment
Add comment · Show 2
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 AlucardJay · Jun 21, 2014 at 06:24 PM 0
Share

If your spikes were a child of an empty gameObject, you could use transform.localPosition . With your current method, you would need to store the starting position of the spikes, then use that in your calculations :

 Vector3 startPos;
 
 // in Start
 startPos = transform.position;
 
 // in method
 if (transform.position.x > startPos.x + X$$anonymous$$aximo) {



avatar image MatheusCroft · Jun 27, 2014 at 06:43 PM 0
Share

I'll have to be putting different values anyways. I wanna know why the values are different than they should really be. I put 3 and it goes to 7, but why?

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Move Forward or Turn based on action recieved. 3 Answers

How can I get the current x position of touch in Android? 2 Answers

Camera rotation around player while following. 6 Answers

GameObject starts drifting on X axis when doing high jump 0 Answers

Is There An OnMouseStop? 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