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 /
  • Help Room /
avatar image
0
Question by MisterFox · Oct 22, 2017 at 11:07 PM · rotationmovementaxisrelative movement

Creating own "x" and "z" axis to move player along?

Hey, horrible beginner here, I had the following plan:

A plane-object (big, transparents cube in this picture) is always setting its transform.position to that of the player (white cylinder). When pushing the right control-stick on the controller left and right, the plane-object rotates (around the player) - which is what I want, because the Main Camera is attached to the plane-object, so it effectively hovers around the player as well. Also attached to the plane-object are four colored squares, the blue one declaring the "front." The front-cube is always facing the camera.

My problem now is that I want to move the player forward, backward, left and right not according to the World Axis, but two Axis established by the colored blocks. So there should be an artificial Z-Axis between the blue and yellow cube, and an artificial X-Axis between the red and green cube, and when I, for example, press "Down", I want the player-object to move towards the blue cube, "along" the Axis between the blue and the yellow cube. Does that make sense?

Long story short, I want to create a simply camera-system where the player's input and the resulting direction of the movement/velocity is relative to the camera-angle, and I thought this could be a good approach if only I can somehow establish that the player should be moving along those two new imaginary axis. Ideally, I would derive the direction that the player-object should be facing from this system as well.

Is that feasible and possible? If so, how? Or is it needlessly complicated, and I'm forgetting something?

Thanks in advance!

alt text

Comment
Add comment · Show 3
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 Hatsuko · Oct 26, 2017 at 02:34 AM 0
Share

Not quite sure I understand... but do you mean that, you want the player's moving direction based on the camera's view? If so than this is doable, but it requires some scripting. If you are very new to scripting, I would recommend you to find in Asset Store or UnityWiki

avatar image MisterFox Hatsuko · Oct 26, 2017 at 08:03 AM 0
Share

Oh, haha, I was definitely implying that I wanted to solve this problem by scripting. I'm still somewhat unexperienced, but not entirely unfamiliar, and yes, you're correct! I want the player to move according to how the camera is rotated. I've since asked somebody else - apparently, a more reasonable solution would be to check for the camera's relative position in world-space and realign the characters' axes to that. I don't need these boxes as an indicator for axes anymore.

Thank you for your advice though! Really nice.

avatar image Hatsuko MisterFox · Oct 26, 2017 at 11:48 AM 0
Share

Oh ok than it shall be fine :D. I'm also not that experienced so I'll just skip explaining details... Here's a quick code I created if you need something. And maybe you can look at this post or google "Unity 3rd Person Controller", there should be a lot of tutorials!

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 // Put this on a object. In play mode press WASD and it should be moving based on camera angle.
 public class Foo : $$anonymous$$onoBehaviour {
 
     public Camera camera;
     public float translationSpeed = 5;
     public float rotationSpeed = 10;
     private float inputAxisHorizontal;
     private float inputAxisVertical;
     private Vector3 desiredTranslation;
     private Quaternion desiredRotation;
 
     // Use this for initialization
     void Start () {
         if (!camera) {
             camera = Camera.main;
         }
     }
     
     // Update is called once per frame
     void Update () {
         inputAxisHorizontal = Input.GetAxis("Horizontal");
         inputAxisVertical = Input.GetAxis("Vertical");
 
         desiredTranslation = new Vector3(inputAxisHorizontal, 0, inputAxisVertical) * Time.deltaTime * translationSpeed;
         desiredTranslation = camera.transform.TransformDirection(desiredTranslation);
         desiredRotation = Quaternion.LookRotation(
             Vector3.RotateTowards(transform.forward, desiredTranslation, Time.deltaTime * rotationSpeed, 0.0F));
 
         transform.Translate(desiredTranslation, Space.World);
         transform.rotation = desiredRotation;
     }
 }
 


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

170 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

how do i reference two input axis at one time on javascript 0 Answers

How to rotate fluently/smoothly? 1 Answer

Rotate Object Axis On Swipe Cam Rotation - Android 1 Answer

Move an object by rotation 0 Answers

How could I rotate an object relative to its movement on an axis? 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