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 /
This question was closed May 24, 2021 at 04:03 PM by Hogge for the following reason:

Solved it myself

avatar image
0
Question by Hogge · May 23, 2021 at 06:10 PM · transform.translate

Local translation error

Hi. As a quick project I've decided to try to make something akin to Wing War, a basic multiplayer flight game.

To achieve this, I've created a "play field" object, where all of the planes are local objects. I move them around the play area using transform.translate. The play field moves through the game world and rotates.

Now, even though the planes are set to translate in the local X and Y axis, they end up moving in the Z-plane.

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class DuelManager : MonoBehaviour
 {
     public GameObject Camera;
     public float CameraSpeed;
     public Transform LookAtPosition;
     public float ForwardSpeed;
     public float XSpeed;
     public float YSpeed;
 
     public AnimationCurve CenterCurve;
 
     public float XBounds;
     public float YBounds;
 
     public float Timer;
     public float TurnDuration;
     public float AverageX;
     public float AverageY;
     public int CurrentAttacker;
     [Serializable]
     public struct Players
     {
         public string PlayerName;
         public Color PlayerColor;
         public GameObject Plane;
         public Input Horizontal;
         public Input Vertical;
         public Input Trigger;
         public float XCoordinate;
         public float YCoordinate;
     }
     [SerializeField]
     public Players[] players;
 
 
     // Start is called before the first frame update
     void Start()
     {
         
     }
 
     // Update is called once per frame
     void FixedUpdate()
     {
         AverageX = 0;
         AverageY = 0;
         transform.Translate(transform.forward * Time.deltaTime* ForwardSpeed,Space.World);
 
         
         Camera.transform.localPosition = Vector3.Lerp(Camera.transform.localPosition, new Vector3(players[CurrentAttacker].Plane.transform.localPosition.x, players[CurrentAttacker].Plane.transform.localPosition.y+10, -10), Time.time*CameraSpeed);
 
         
 
         if (players[1].Plane.transform.localPosition.x >= 0)
         {
             players[1].Plane.transform.Translate(transform.right * Time.deltaTime* -CenterCurve.Evaluate(players[1].Plane.transform.localPosition.x), Space.Self);
         }
         else
         {
             players[1].Plane.transform.Translate(transform.right * Time.deltaTime * CenterCurve.Evaluate(-players[1].Plane.transform.localPosition.x), Space.Self);
         }
 
         players[1].Plane.transform.Translate(transform.right * Time.deltaTime * Input.GetAxis("Horizontal") * XSpeed, Space.Self);
         players[1].Plane.transform.Translate(transform.up * Time.deltaTime * -Input.GetAxis("Vertical") * YSpeed, Space.Self);
 
         players[1].Plane.transform.localPosition = new Vector3(players[1].Plane.transform.localPosition.x, players[1].Plane.transform.localPosition.y, 50);
 
         for (int i = 0; i < players.Length; i++)
         {
             if (i == CurrentAttacker)
             {
 
             }
             else
             {
                 AverageX += players[i].Plane.transform.localPosition.x;
                 AverageY += players[i].Plane.transform.localPosition.y;
             }
         }
 
     
 
 
         AverageX = AverageX / players.Length-1;
         AverageY = AverageY / players.Length-1;
         LookAtPosition.localPosition = new Vector3(AverageX, AverageY, 50);
 
    
             Camera.transform.LookAt(LookAtPosition.position);
 
 
         transform.Rotate(0, AverageX*0.01f, 0, Space.World);
 
 
     }
 }
 

In the above code, I force the plane to its correct Z-position on every frame, which initially seems to fix the problem. However, once the play field approaches a rotation of 90 degrees, movement becomes sluggish and the aircraft centering feature goes berserk. I can't figure out why this is as the plane continues to have a rotation of 0,0,0.

For reference, here's a video of what happens:: Video

Any ideas?

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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

117 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

Related Questions

Invisible barrier transform.Translate error 1 Answer

moving object on x axis without affecting z axis 1 Answer

Make an object that moves relative to the touch more natural 0 Answers

Block Game Object interaction with another Game Object with kinematic active 0 Answers

Move two objects at same time as they are one single object 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