- Home /
Moving replacing center object with orbiting object
Hey there, i'm pretty new at scripting. I'm working on a project, my scene is made up of the following. A Sphere in located in the middle of the scene, and 4 other spheres are orbiting around the center sphere. I have a camera focusing on the center object that can rotate around it and zoom in and out with smooth motion. My problem :/ is that i want to make a script that will allow me to click on one of the 4 sphere in orbit, to where the sphere that i selected will move in and replace the center sphere, and the center sphere will move out, and orbit the new center sphere.
Could anyone provide me with a script can do want i'm asking for? or just help me make one?;)
Thank you for the upcoming help ;)
Why did you post the camera-orbit script? It's not even relevant here! You should just post the relevant interfaces to it- what functions you have to call and what variables need to be changed to set it up. If you don't want to 'release any details', I'm afraid I won't be able to help you that much.
Answer by ByteSheep · Dec 05, 2011 at 08:28 PM
This function could probably be a good start for what you're looking to do:
http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnMouseDown.html
You could use it to detect whether you clicked on a sphere - something like:
var target : Transform;
var MoveSpeed : float = 2;
function OnMouseDown () {
transform.LookAt(target);
transform.position += transform.forward * MoveSpeed * Time.deltaTime;
}
This script would then need to be added to each sphere! This is just a quick idea, there is for example a problem = since the transform.position part is not in the Update function, the sphere won't move forwards properly.. It should be simple enough to move the transform.position etc part to the Update, but tell me if you need help with that.. The "transform.LookAt(target);" part is to make sure the sphere is looking at the center sphere and could perhaps also be placed into the Update function! Also, you will have to assign the center sphere to the "target" variable in the Inspector window. Good luck!
Hey thank you for the answer, that is what i'm trying to do, but my scripting knowledge is very limit, I would treasure any help I could get ;) So if you can maybe explain how to setup/make a script for that, it would be awesome ;)
Hey thank you for the answer, that is what i'm trying to do, but my scripting knowledge is very limit, I would treasure any help I could get ;) So if you can maybe explain how to setup/make a script for that, it would be awesome ;)
This is a good page to look at, showing how to create and add a script to a game object:
http://unity3d.com/support/documentation/$$anonymous$$anual/Scripting.html
Once you have created the script and added it to the game object (in this case needs to be added to all spheres), you can paste the code I have given you as a starting point into the script and save it. Once you have done this you will have to make some changes to the code I have given you (explained in other answer)..
If you are still having troubles with the basics, there are lots of helpful pages you can look at. Please let me know if you have already managed to add the script to the game objects and I will try and help you with the necessary code you would need.
Oh and the scripting language I have used is JavaScript so you will need to create a JavaScript file (not Boo or C sharp)
Your answer
Follow this Question
Related Questions
Mouse Orbit + Move Object + Follow Problem 1 Answer
Camera Movement issue 1 Answer
Orbit around an object 0 Answers
3rd person camera/movement 2 Answers
First person camera restriction. 1 Answer