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 Little_Dizzle · Oct 31, 2014 at 07:33 PM · rotationgravityforcefps controller

Rotational Gravity - Camera and Force problems

I'm trying to emulate the rotational gravity that would exist on a cylindrical space station as such

alt text

I am attempting to do so buy this method...

find the player z, then draw line from the center of cylinder with the same z to the player. Apply force in that direction then rotate player with the cylindrical center defined as up

 public class rotationalGravity : MonoBehaviour {
 
     public GameObject player;
     Vector3 middlePoint;
     Vector3 playerV;
     Vector3 playerPos;
     Vector3 forceDirection;
     Rigidbody playerRidge;
 
     
     void Start () {
 
         playerV = player.transform.position;
         middlePoint = new Vector3 (0, 0, playerV[2]); // sets middle point to have same z as player
         playerRidge = player.AddComponent<Rigidbody>(); // causes player to shoot up for some reason
     }    
     void Update () {
 
 
         playerPos = new Vector3 (playerV [0], playerV [1], playerV [2]); 
         middlePoint.z = playerV [2];
 
         forceDirection = middlePoint + playerPos; // gets direction to apply force?
 
         //Physics.gravity = forceDirection; 
     
         player.transform.Rotate (Vector3.forward * Time.deltaTime); // another way i was trying to rotate player
 
         playerRidge.transform.forward = Physics.gravity; // trying to rotate player around the center of cylinder
 
         playerRidge.AddForce(-forceDirection * Time.deltaTime);  // supposed to apply force to player in the direction from the middle


When it runs the player(which is the default FPS Controller) just floats up and passes through everything.

alt text

The camera rotation is way off too. Do I need to make changes to the FPS Controller to get the camera and controls to rotate correctly? And what am I doing wrong in trying to apply the force to the player? This project is being made to learn a lot of the ropes.

EDIT: I'd rather implement a system of this style rather than rotate the cylinder as down the line there will be multiple enemies and potential a second player.

unity.png (268.8 kB)
Comment
Add comment · Show 8
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 robertbu · Oct 31, 2014 at 07:34 PM 0
Share

The FPS controller will not handle arbitrary rotations well. Consider rotating your camera and cylinder rather than the character.

avatar image MrSoad · Oct 31, 2014 at 09:58 PM 0
Share

If you were not trying to integrate this into the FPS controller then I could certainly help you with this, but as robertbu says this adds many complications...

avatar image Little_Dizzle · Oct 31, 2014 at 10:56 PM 0
Share

@ $$anonymous$$rSoad if I went with robertbus idea, how would you suggest doing it?

avatar image Fornoreason1000 · Oct 31, 2014 at 11:27 PM 0
Share

you could try rotating the gravity itself within "FPS" Controller, that's way you can have enemies pursuing/Ambushing you. then doing a check to make sure the up direction is the opposite direction of gravity....(then snapping or very quickly rotating the character until it is)

Ever played Ratchet & Clank series? they have these scenarios quite often, but even more complex, you might be able to learn a bit how they work by testing it...I've learnt a lot form just testing other games features then replicating their behavior in unity.

you basically need to rewrite FPS controller/Character $$anonymous$$otor to allow it, as Robertbu said, it currently won't handle them well... (if at all)

As for rotating the cylinder, that causes potential problems such as viewing another section of the level while inside it.

avatar image MrSoad · Oct 31, 2014 at 11:30 PM 0
Share

Sorry can't help with that, I would write my own character controller script from scratch, starting with basic movement, then applying the cylindrical gravity code, then working through the rest of what the FPS controller does and implementing that in a way that works with my gravity character controller...

(Edit : What Fornoreason1000 says about playing games and trying to recreate their mechanics is spot on! This is a great way to learn. I would not rotate the cylinder as you will learn far more the other way, also rotating the cylinder can make the enemy scripting harder. If you get it working for your player(as is) then much of your player script will be transferable to the enemy scripts.

Are you going to have more than just one cylinder section and if so how do you plan on linking them? )

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by MrSoad · Nov 01, 2014 at 12:59 AM

Ok, if you are going to go with my way then start simple! Then build upon these working foundations.

For some info on how to align your player rotation for your current player position in relation to your gravitational pull/push vector position take a look at my answer to this :

http://answers.unity3d.com/questions/819101/self-levelling-a-gameobject.html

You will be pushing away rather than pulling toward!!! This script shows you how to keep the player object correctly aligned in terms of rotation for you current position in relation to the gravitational position vector. You will still need to apply your gravity force in the right direction for current position in relation to your gravity point position.

For the curved connecting sections it will probably be best to model the curve connections in a 3D package such as Blender. You will put the anchor point of the connection mesh section at the point where you want the gravity calculations to adhere to. Then use a trigger script to switch between the cylinder section central line gravity point and the connection(semi spherical) gravity point.

Once you have this working you can then start to reintroduce the complex FPS controller attributes.

As stated above, if done this way then apart from the enemy object AI(relating to intelligent movement) the basic scripts that you write here for gravity etc will be directly transferable to your enemy objects.

Hope this helps :)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Scripting, Rotate and set gravity on collision 1 Answer

Applying force with respect to angle with the ground? 1 Answer

Teleport and change direction of current velocity. 2 Answers

FPS Rigid Body Controller Force Control Unity 5 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