- Home /
Walking & Gravity
Hi Everyone! I wanna do a game that every level in the game is a huge shape (like cube), and basically - I walk on this shape (actually there is more shapes like moons on the biggest one).
But since I am not good in unity and I don't find any teacher or something, I don't know how to do the basics of this game - gravity to the main shape, gravity to eack moon shape, the ability to jump from shape to shape, the camera that will be changed when I'll change side of the shape (or allways, if the shape in ball), and I dont know how to do that the player will walk like the camera, wont fall while turning from side to side, (and actually I don't know how to rotate him too).
If someone will teach me all that I would be thankful to him very much. My skype is yonisimian (I don't think that it is possible to include all this codes in one answer, and besides - I also wanna learn from this, not just copy :) .
Answer by fardinnn · Aug 08, 2013 at 08:39 AM
use Physics.gravity = Vector3(gravity direction * size) you can Obtain gravity direction in several ways : 1 : if your shape is simple by center and rotation of model and your position calculate the direction 2 : the simpler way is send a ray from you position to center of shape and coll that shape , then get surface normal , for this you can use : Physics.Raycast http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html and RaycastHit.normal http://docs.unity3d.com/351/Documentation/ScriptReference/RaycastHit-normal.html
A small note to this, if you have several rigidbodies that uses gravity you would be better off controlling each rigidbody separately to set their gravity direction as described in answer. In other words rigidbody.AddForce(normalizedGravityDirection*gravity).
Answer by Marksmir · Aug 08, 2013 at 08:22 AM
Sounds like you have no unity experience- if I was you I would pay a teacher for some basic lessons (should only take about 6 hours). However I can say that you can do the gravity but clicking on the shape then inspector then gravity (tick box). The controller is a fairly simple script- if I were you I would download it from the assets or something. The player (first person) is an object (can't remember of the top of my head for some reason which object it is.) Basically you create an object- drag the camera onto it as a main object and add the first person script to it.
Hope this helps!