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 /
This question was closed Dec 27, 2011 at 09:35 AM by BlacKatFever for the following reason:

Other

avatar image
0
Question by BlacKatFever · Nov 21, 2011 at 09:41 AM · worldspacelocalspacetransform.lookatconstantforce

Applying Constant Force to Object A using Object B's Vectors.

Hey all,

I'm having a hard time with Constant Force and making it work in my project. Could you take a look at what I'm doing and tell me what I'm doing wrong or if I should look for another approach?

The basic gist is that I have a trigger box (wind zone) that I instantiate with a flick (swipe). I take the starting coordinate of my flick and assign it as a HitPointA using a Raycast. I then use the ending coordinate to get HitPointB, also using a Raycast.

Then, when my rectangular-shaped "wind zone" comes into play, it instantiates at HitPointA and then use Transform.LookAt to rotate the object to face HitPointB. This gives me a definite Vector3.Forward.

What I would like to do is set it so that when my primary game object, a flower petal, touches this wind zone, the flower will move along the wind zone in a direction that matches HitPointA to HitPointB.

alt text

Here the petal is falling, it's Z-coordinate is locked because this is a 2D game. It is about to hit the wind zone trigger box.

alt text

The problem is that "pointy" end of my wind zone (the clock hand, if you will) that points at HitPointB runs along the Z-axis. So my code (listed below - attached to my WindZone prefab) automatically tries to assign a ConstantForce value of Z: 10 to my petal.

All I want, is for my petal to travel within the wind zone in the direction that it is pointing. Thinking of a clock, if the hour hand is point at 3'oclock, I'd like it to travel from the center of the clock to towards the 3:00 position. If the hour hand is point at 9:00, then I'd like for it to travel towards the 9:00 position.

Any ideas on what I'm doing wrong or how I can fix this?

 using UnityEngine;
 using System.Collections;

 public class WindStream : MonoBehaviour
 {
 GameObject petal;
 Vector3 streamDir;
 public float gravityTimer; // disable gravity within the stream
 public bool startTimer; //trigger needed to start timer

 void Start()
 {
   petal = GameObject.FindGameObjectWithTag("Petal");
   streamDir = Vector3.Forward;
   gravityTimer = 1.0f;
 }

 void Update()
 {
   if (startTimer == true)
   {
     gravityTimer -= Time.deltaTime;
     if(gravityTimer <= 0)
     {
       ToggleGravity();
       ResetTimer();
       startTimer = false;
     }
   }
 }

 void OnTriggerEnter(Collider other)
 {
   if(other.gameObject.name == "Petal")
    {
     Debug.Log("Contact!");

     startTimer = true;
     petal.constantForce.relativeForce = streamDir * 10;
    }
 }

 void ToggleGravity()
 {
   petal.rigidbody.useGravity = false;
 }

 void ResetTimer()
 {
   gravityTimer = 1.0f;
 }

}

Comment
Add comment · Show 1
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 BlacKatFever · Nov 21, 2011 at 10:17 AM 0
Share

I've found that if I write the following -

transform.LookAt(swipeTeset.needlePoint$$anonymous$$agnet);

transform.Rotate(new Vector3(0, 90, 0);

That the X-axis is now pointing where I want my flower petal to go. The problem is that when the flower enters the trigger box, it's still moving according to its own coordinates, not the trigger box's. :(

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Clamping rotation doesn't work when local axis is different from global 0 Answers

How do I make an object move on the world space rather than the local space? 1 Answer

Is it possible to convert Mesh Vertices Local Position to World Space? 0 Answers

How to use Transform.TransformDirection of another transform to affect a separate Transforms local rotation? 0 Answers

Transform.rotation is setting local rotatoin 0 Answers


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