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 Aug 03, 2014 at 03:31 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Dr_Horrible · Aug 03, 2014 at 01:44 PM · transformworldspace

transform in worldspace

Hi guys, i need some help in what i guess is actually a quite simple task, but I couldn't figure it out for two hours.

I have a script attached to my enemy, that makes him wobble in the air:

transform.position += amplitude*(Mathf.Sin(2*Mathf.PI*frequency*Time.time) - Mathf.Sin(2*Mathf.PI*frequency*(Time.time - Time.deltaTime)))*transform.up;

The problem: since my enemy is angled by about 30° on the x axis, he wobbles deeper with each cycle, causing him to go through the ground.

I suppose i have to generate the direction in relation to world space, rather than its local space. But what do i use instead of transform.up, to get world space coordinates?

thanks in advance

Dr. H

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 meat5000 ♦ · Aug 03, 2014 at 02:08 PM 0
Share

Vector3.up

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by robertbu · Aug 03, 2014 at 02:13 PM

'transform.up' is the world direction the top of your object. If you want the world up, then you can use Vector3.up. Unless there is other code impacting this object's rotation elsewhere, I cannot see the use of transform.up as the reason for the larger cycles. In looking at your code, I would suspect that variations in 'deltaTime' would make more of an impact. I only see this one line out of context, but I'd do an absolute movement based on a start position rather than rely on relative movement if I could. Example.

 #pragma strict
 
 var amplitude = 1.0;
 var frequency = 2.0;
 private var start : Vector3;
 
 function Start () {
     start = transform.position;
 }
 
 function Update () {
     transform.position = start + amplitude*(Mathf.Sin(2.0 * Mathf.PI*frequency * Time.time)) * transform.up;
 }

This way no errors of any sort will creep in over time.

Comment
Add comment · Show 1 · 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 Dr_Horrible · Aug 03, 2014 at 02:42 PM 0
Share

first off, thanks for the reply.

Your code did the intended job.

Unfortunately, i do have other scripts, affecting the enemies movement. These are in conflict with the total movement.

However they work on the x and z axis, so I now only apply the total y value.

It's not exactly beautiful (neither code nor game-esthetics wise) but unless someone has an easy way to fix this elegantly, it's a workaround i can live with - for now, anyways.

cheers

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

transform.position is giving me local space 1 Answer

How to move two same Objects at the same place in different scenes? 1 Answer

Convert terrain map coordinates (GetDetailLayer) into world position 0 Answers

Programatically calculate child offset in world space 1 Answer

Is there an end to Unity world space? 3 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