Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 gmancannon03 · Jun 05 at 09:35 PM · rotationmovementspace shootertilttilting

How to get moving player to tilt when turning

Hello,

I am pretty new to Unity, and am working on a simple, 2D Top-Down flying game. When my spaceship thing is turning, I would like it to be able to tilt side to side, to make things a little more interesting. The input is simple left/right, and the ship will be constantly moving. I have a movement script that works:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class ShipMovement : MonoBehaviour
 {
     public float Speed;
     public float Acceleration;
 
     Rigidbody2D rb;
 
     public float RotationControl;
 
     float MovY, MovX = 1;
 
 
 
     // Start is called before the first frame update
     void Start()
     {
         rb = GetComponent<Rigidbody2D>();
     }
 
     // Update is called once per frame
     void Update()
     {
         MovY = SimpleInput.GetAxis("Horizontal");
     }
 
 
     private void FixedUpdate()
     {
         Vector2 Vel = transform.up * (MovX * Acceleration);
         rb.AddForce(Vel);
 
         float Dir = Vector2.Dot(rb.velocity, rb.GetRelativeVector(Vector2.up));
 
         if (Acceleration > 0)
         {
             if (Dir > 0)
             {
                 rb.rotation += MovY * RotationControl * (rb.velocity.magnitude / Speed);
             }
             else
             {
                 rb.rotation -= MovY * RotationControl * (rb.velocity.magnitude / Speed);
             }
         }
 
         float thrustforce = Vector2.Dot(rb.velocity, rb.GetRelativeVector(Vector2.right)) * 2.0f;
 
         Vector2 relForce = Vector2.left * thrustforce;
 
         rb.AddForce(rb.GetRelativeVector(relForce));
 
         if (rb.velocity.magnitude > Speed)
         {
             rb.velocity = rb.velocity.normalized * Speed;
         }
     }
 }
 

And I have thrown together a visual script for the Y-axis tilt: alt text

(I could probably convert that to C# pretty easily if that helps)

Anyway, both of those scripts work fine, separately, but when I try to use them together, or use the movement script on a Parent object and the tilt visual script on a child object, neither will move. I've been working on this problem for a while, and it seems like I've tried everything, including rotation and tilt on the same object (same result), and a bunch of other things (localRotation, snapping an object back and forth underneath the spaceship, then having it 'look' toward that object, etc.) Nothing has worked so far. It seems that movement/rotation and tilt are mutually exclusive, and any answers I have found elsewhere don't seem to work.

I'd really appreciate any ideas on how to get a constantly moving object to rotate/turn, and tilt at the same time!

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

· 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

230 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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 to make a RigidBody not go into ground when tilted foward? 2 Answers

My vehicle wont perform both the Tilt and Turn 0 Answers

How do I make a 2D object face the direction it is moving in top down space shooter 1 Answer

add force at position with respect to rotation 1 Answer

Tilt an object when rotating and set it back to normal afterwards 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