Question by
Whitebear_Hsieh · Jan 10, 2017 at 07:29 AM ·
player movementsphererestrictions
Unity 3D player movement boundary (Sphere object)
I want to restrict player movement in the sphere ranges, the schematic diagram show as below, the maximum movement distance is sphere radius. if player movement out of ranges, then restrict player position to sphere max radius range (X, Y). how can I write C# code to implement it, many thanks for your help.
This is my current step:
step1: create 3D sphere, then I change sphrer position Z-axis to -10, scale value X is 35, Y is 1, Z is 35
Step2: create C# code append to sphere object
using UnityEngine;
using System.Collections;
public class MoveBoundary : MonoBehaviour {
public Transform Ninja; //Ninja Object
// Update is called once per frame
void Update () {
Vector3 pos = Ninja.position;
................
}
}
未命名.png
(10.1 kB)
Comment
Your answer
Follow this Question
Related Questions
Icosphere texture seam 0 Answers
I don't if I am stupid,but it confuses me really. 1 Answer
Instantiate objects around a sphere 0 Answers
I have rotation problem, I look forward to helping. 0 Answers
What does the other in OnTriggerEnter/Stay/Exit mean? 0 Answers