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 murkertrer · Apr 23, 2014 at 10:29 PM · orbitplaceshieldaround

Placing an object around character in 3d space?

Hi!

Im trying to make a shield that can be placed around the player, in the player desired position, in the 3d world, in order to block some shots...

I was thinking on making a prefb, and instantiating it on the desired position, with some sort of orbit. Any Idea on how to make this? Here an ilustration.alt text

I apreciate it. :D

shield.png (9.9 kB)
Comment
Add comment
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

1 Reply

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

Answer by robertbu · Apr 24, 2014 at 06:05 AM

Why not just have a Quad as a child of the player. You can turn the renderer and the collider on and off to turn the shield on and off. You can move the shield to desired position as needed. No reason to instantiate a game object. You don't give any details on the movement code, so I cannot be more specific on how to position the Quad.

Comment
Add comment · Show 4 · 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
avatar image murkertrer · Apr 24, 2014 at 02:58 PM 0
Share

Hi Robertu, Thank you for taking some time.

I'm quite new at this, I dident post the code because i dident thought it was relevant *silly me.

I was trying to undertstand what quad was but I think it is kind of difficult (been progra$$anonymous$$g for 1 week :s)

Here is my code, #pragma strict // These variables are for adjusting in the inspector how the object behaves var maxSpeed = 8.000; var force = 20.000; var jumpSpeed =5.000; //Eulers Var var yRotation : float = 20.0; // These variables are there for use by the script and don't need to be edited private var state = 0; private var grounded = false; private var jumpLimit = 0; //--------------------------------------------------------------------------------- // Don't let the Physics Engine rotate this physics object so it doesn't fall over when running function Awake () { rigidbody.freezeRotation = true; } //--------------------------------------------------------------------------------- // This part detects whether or not the object is grounded and stores it in a variable function OnCollisionEnter () { state ++; if(state > 0) { grounded = true; } } //--------------------------------------------------------------------------------- function OnCollisionExit () { state --; if(state < 1) { grounded = false; state = 0; } } //--------------------------------------------------------------------------------- // This is called every physics frame function FixedUpdate () { // Get the input and set variables for it var jump = Input.GetButtonDown ("Jump"); var horizontal = Input.GetAxis("Horizontal"); var vertical = Input.GetAxis("Vertical"); // Set the movement input to be the force to apply to the player every frame horizontal *= force; vertical *= force; // If the object is grounded and isn't moving at the max speed or higher apply force to move it if(rigidbody.velocity.magnitude < maxSpeed && grounded == true) { rigidbody.AddForce (transform.rotation * Vector3.forward * vertical); rigidbody.AddForce (transform.rotation * Vector3.right * horizontal); } // This part is for jumping. I only let jump force be applied every 10 physics frames so // the player can't somehow get a huge velocity due to multiple jumps in a very short time if(jumpLimit < 1) jumpLimit ++; if(jump && grounded == true && jumpLimit >= 1) { rigidbody.velocity.y += jumpSpeed; jumpLimit = 1; } } //--------------------------------------------------------------------------------- //Problema Relacionado con los frames, mover por tiempo / $$anonymous$$ovimiento de La esfera del dragon function Update (){ $$anonymous$$ovement(); } //--------------------------------------------------------------------------------- function $$anonymous$$ovement(){ transform.eulerAngles = Vector3(transform.localEulerAngles.x, Camera.main.transform.localEulerAngles.y, transform.localEulerAngles.z); } //---------------------------------------------------------------------------------

avatar image murkertrer · Apr 24, 2014 at 02:59 PM 0
Share

Sorry for the bad format

pragma strict

// These variables are for adjusting in the inspector how the object behaves var maxSpeed = 8.000; var force = 20.000; var jumpSpeed =5.000;

 //Eulers Var
 var yRotation : float = 20.0;
  
 // These variables are there for use by the script and don't need to be edited
 private var state = 0;
 private var grounded = false;
 private var jumpLimit = 0;
  
  
  //---------------------------------------------------------------------------------
 // Don't let the Physics Engine rotate this physics object so it doesn't fall over when running
 function Awake ()
 { 
     rigidbody.freezeRotation = true;
 }
 
 //---------------------------------------------------------------------------------
 // This part detects whether or not the object is grounded and stores it in a variable
 function OnCollisionEnter ()
 {
     state ++;
     if(state > 0)
     {
         grounded = true;
     }
 }
 
 //---------------------------------------------------------------------------------
 function OnCollisionExit ()
 {
 state --;
     if(state < 1)
     {
         grounded = false;
         state = 0;
     }
 }
 
 //--------------------------------------------------------------------------------- 
 // This is called every physics frame
 function FixedUpdate ()
 {
  
  // Get the input and set variables for it
     
     var jump = Input.GetButtonDown ("Jump");
     var horizontal = Input.GetAxis("Horizontal"); 
     var vertical = Input.GetAxis("Vertical"); 
  
     // Set the movement input to be the force to apply to the player every frame
     horizontal *= force;
     vertical *= force;
  
     // If the object is grounded and isn't moving at the max speed or higher apply force to move it
     if(rigidbody.velocity.magnitude < maxSpeed && grounded == true)
     {
         rigidbody.AddForce (transform.rotation * Vector3.forward * vertical);
         rigidbody.AddForce (transform.rotation * Vector3.right * horizontal);
     }
  
     // This part is for jumping. I only let jump force be applied every 10 physics frames so
     // the player can't somehow get a huge velocity due to multiple jumps in a very short time
     
     if(jumpLimit < 1) jumpLimit ++;
     if(jump && grounded == true && jumpLimit >= 1)
     {
         rigidbody.velocity.y += jumpSpeed;
         jumpLimit = 1;
     }    
  }
 
 //---------------------------------------------------------------------------------
 //Problema Relacionado con los frames, mover por tiempo / $$anonymous$$ovimiento de La esfera del dragon 
 function Update (){
  
 $$anonymous$$ovement();
 
         
 }
                 
 //---------------------------------------------------------------------------------                
 function $$anonymous$$ovement(){
     transform.eulerAngles = Vector3(transform.localEulerAngles.x, Camera.main.transform.localEulerAngles.y, transform.localEulerAngles.z);
 }
     
 //---------------------------------------------------------------------------------
     
     
avatar image robertbu · Apr 24, 2014 at 07:23 PM 0
Share

The code you posted appears to be for the character. What I'm wondering is how you are going to move the Quad. Is it just 2D or a 3D rotation? What Inputs define the rotation? BTW, a Quad is a basic game object. You can create one by:

 GameObject > Create Other > Quad

It is just a two triangle plane with a natural vertical orientation and a collider.

avatar image murkertrer · Apr 24, 2014 at 08:44 PM 0
Share

It is 3d rotation.

I think I have found the solution, I modified the orbit script prefab, and just substracted 180 degrees so that it tilts in front of the character XD

 var target : Transform;
 var distance = 20.0;
 
 var xSpeed = 150.0;
 var ySpeed = 120.0;
 
 var y$$anonymous$$inLimit = 25;
 var y$$anonymous$$axLimit = 60;
 
 private var x = 0.0;
 private var y = 0.0;
 
 
 
 function Start () {
     transform.position = Vector3(0,10,0);
     var angles = transform.eulerAngles;
     x = angles.y;
     y = angles.x;
 
     // $$anonymous$$ake the rigid body not change rotation
        if (rigidbody)
         rigidbody.freezeRotation = true;
 }
 
 function LateUpdate () {
     if (target) {
         x += Input.GetAxis("$$anonymous$$ouse X") * xSpeed * 0.01;
         y -= Input.GetAxis("$$anonymous$$ouse Y") * ySpeed * 0.01;
          
          y = ClampAngle(y, y$$anonymous$$inLimit, y$$anonymous$$axLimit);
                 
         var rotation = Quaternion.Euler(y, x+180, 0);
         var position = rotation * Vector3(0.0, 0, -distance) + target.position;
         
         transform.rotation = rotation;
         transform.position = position;
     }
 }
 
 static function ClampAngle (angle : float, $$anonymous$$ : float, max : float) {
     if (angle < -360)
         angle += 360;
     if (angle > 360)
         angle -= 360;
     return $$anonymous$$athf.Clamp (angle, $$anonymous$$, max);

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

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Move camera around object IOS 2 Answers

Making an object rotate around a sphere 1 Answer

Rotating camera around object up/down problem 0 Answers

How to Rotate camera around object SMOOTHLY when using Input.GetKeyDown 1 Answer

Orbit Sim without Physics Engine 1 Answer


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