The production process

Create a new sphere in the scene (Planet) And a capsule (Player), Scale and add materials appropriately , Here, the capsule will be regarded as a player

Then set the camera to capsule (Player) A child object of



Adjust the appropriate camera angle by yourself

New script GravityArrtacter, Add to Planet On

public class GravityAttracter : MonoBehaviour
{
public float gravity = -10; // The magnitude of gravity
public void Attract(GameObject obj) // The way to attract objects , Pass in the object that needs to be attracted
{
Transform body = obj.GetComponent<Transform>();
Vector3 gravityUp = (body.position - transform.position).normalized; // Planet to player vector
Vector3 bodyUp = body.up; // The positive upward direction of the object being attracted body.GetComponent<Rigidbody>().AddForce(gravityUp * gravity);// Attract objects , The magnitude of gravity is negative , The direction changes to the direction of the object to the planet // Rotate an axis from parameter 1 to parameter 2 ( World space ) The direction of , Here is to rotate the top of the object to the direction of gravity ,
// But an axis cannot determine the state of rotation of an object ,* body.rotation Get the target direction that the object needs to rotate
Quaternion targetRotation = Quaternion.FromToRotation(bodyUp, gravityUp) * body.rotation;
// Interpolation , rotate
body.rotation = Quaternion.Slerp(body.rotation, targetRotation, 50 * Time.deltaTime);
}
}

Set your own gravity , Negative numbers here indicate the direction of gravity

New script Body, Add to Player On

public class Body : MonoBehaviour
{
public FauxGravityAttracter attracter; // Declare the planet's gravity
private Rigidbody myRigidbody; void Start()
{
myRigidbody = gameObject.GetComponent<Rigidbody>(); // Get the object rigid body
myRigidbody.constraints = RigidbodyConstraints.FreezeRotation;// Cancels rigid body collision rotation effects
myRigidbody.useGravity = false; // Cancel the influence of world space gravity
} void Update()
{
attracter.Attract(gameObject);// Pass in the parameter , The object is attracted
}
}

Set the corresponding parameters

newly build PlayerController, Add to Player On

public class PlayerController : MonoBehaviour
{
public float moveSpeed = 15f;
private Vector3 moveDir;
private Rigidbody myRigidbody; void Start()
{
myRigidbody = gameObject.GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
myRigidbody.MovePosition(myRigidbody.position + transform.TransformDirection(moveDir) * moveSpeed * Time.deltaTime);
} void Update()
{
moveDir = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")).normalized;
}
}

Set the movement speed

This simulates walking on the surface of the planet

Unity Make more articles about a small planet

  1. Wu Yuxiong Bootstrap Front end framework development ——Bootstrap Button : Make a little button

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. utilize yacc and lex Make a small calculator

    Bought a book < Self made programming language >, This book is a bit difficult , For now, just look at the first two chapters , It is estimated that the following chapters , I won't watch it recently , It's really hard !! Because I am in a weak school , There is no compiling principle in the school curriculum , So I want to see these two chapters , understand ...

  3. Pygame: Write a little game label : pythonpygame game 2017-06-20 15:06 103 Human reading Comment on (0)

    The final examination of the university is finally over , Ushered in the summer vacation and the long senior " free " During the holiday . Of course, you have to do it yourself " play " 了 . I've been learning Python, It is intended to be used in machine learning and deep learning Python ...

  4. 【flash】 About flash It's transparent gif A little trick for

    About flash It's transparent gif A little trick for Or a place to pay attention to 1. Export movie |gif, It must be opaque .2. Want a transparent background , It has to be released .3.flash I want to publish gif Animation words , There can't be words , ...

  5. Jingdong imitation of the top search bar effect of a small production demo

    Recently imitates the Jingdong top search bar effect to make a small demo, It's posted here , If it is useful in the future, you can refer to it , The code is as follows #define kScreenWidth [UIScreen mainScreen].bounds.s ...

  6. 【Unity skill 】 Make a simple NPC

    1. Write it at the front I saw it the other day cgcookie A tutorial for , Learned how to make a copy of an existing character model NPC figure , It's fun , Sort it out and put it on your blog ! Let's take a look at the final effect in the tutorial . Isn't it like a ghost ~ Here is ...

  7. Unity Game development skills Collection: making a telescope and viewer camera

    Unity Game development skills Collection: making a telescope and viewer camera Unity Make a telescope in Telescope made in this section , When the left mouse button is pressed , The view you see will become larger : When no longer pressed , Will slowly shrink to the original view . What often appears in the game ...

  8. Wu Yuxiong Bootstrap Front end framework development ——Bootstrap Button : Make a super small button

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  9. use Python Make an art signature widget , Design an elegant signature for yourself

    There are many scenes in life that need our signature ( Signature ), If it's some unimportant scene , It doesn't matter whether our signature is good or not , But if it's something more important , If our signature is poor , It may leave a bad impression on others , As the saying goes, words are like people , Ben ...

  10. unity introduction — Five minutes to make a theoretical game

    unity introduction Preface : This is not the party title , Although it's all basic operations , But it includes the basic process , Compared with the various pictures in my mind , It's a little bit more realistic for beginners . Here's a couple of sentences ,unity Foreign official website download will recommend you to watch a short video , Domestic official website ...

Random recommendation

  1. SOA Integration Repository Error:Service Provider Access is not available.

    stay Oracle EBS Integration Repository in , Open one Webservice, There was a warning . english : Warning Service Provider Access is no ...

  2. jenkins2 pipeline Grammar quick reference

    jenkins2 pipeline A quick reference to the grammar commonly used in . Article from :http://www.ciandcd.com The code in this article comes from github download : https://github.com/ciand ...

  3. centos 6.4 /var/log/secure The problem of not logging

    Make sure the log service is on first : You might as well restart the log service : Due to the present RHEL 6/centos 6 Has been used rsyslog To replace the syslog., So don't look for /etc/syslog.conf 了 : Restart command :/etc/init. ...

  4. Glowing input box ( pure css Realization )

    css Code : input{width: 200px;height: 40px;} input.focus{border-color: #08c;box-shadow: 0 0 4px #8bd6fb; ...

  5. ADO.NET( One )

  6. 【ZOJ 3609】Modular Inverse The smallest inverse of multiplication

    The modular modular multiplicative inverse of an integer a modulo m is an integer x such that a-1≡x  ...

  7. dva, Clear module data

    Preface : In the project , Too many modules ,dva Use namespace After separating the module , If the corresponding data is not cleared after the module is unloaded , The next time you enter , There may be remnants of the last data . For example, the details page , from A After the product details page leaves , Return to select B Goods enter , ...

  8. Of the observer model ES6 Realization ( One )

    One . Reference link https://github.com/JacksonTian/eventproxy/tree/master/lib Two . Code implementation // eventProxy.js 'use strict ...

  9. Tinyos Learning notes ( Two )

    1.TinyOS communication tools java serialApp -comm [email protected]/dev/ttyUSB0:telosb java net.tinyos.tools.L ...

  10. How to improve mysql replication Performance of &amp;amp; Multi threaded transmission of binary logs

    1, It's best to use intranet or dedicated link to transmit binlog data ( Gigabit nics . If not enough ,bounding technology , Expand bandwidth ) stay my.cnf Forced use of Intranet in ip To transmit data bind-address=ip2, Save binaries in a separate file ...