Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Eirikir · Aug 10, 2011 at 06:38 PM · ontriggerenterprojectileteleport

Teleporting projectiles, and maintaining speed

Hi, I'm trying to teleport a projectile from one teleport to another, by shooting into the first one. I also want the projectiles speed to be maintained when exiting the second teleporter.

This is my code:

 #pragma strict
 var teleportTo : Transform;
 
 function OnTriggerEnter (col : Collider)

{ col.transform.position = teleportTo.position; }

The projectile does indeed get teleported as wanted, but it does not keep its speed and will immediately drop to the ground. Any help would be appreciated :)

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

3 Replies

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

Answer by Blankzz · Aug 10, 2011 at 10:48 PM

Just as Unamine suggested. Something like;

 var teleportTo : Transform;
 
 function OnTriggerEnter (col : Collider)
 { 
     var vel : Vector3 = col.rigidbody.velocity;
     col.transform.position = teleportTo.position;
     col.rigidbody.Addforce(vel, ForceMode.Acceleration);
 }
Comment
Add comment · Show 7 · 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 Eirikir · Aug 10, 2011 at 11:35 PM 0
Share

Sorry no, this didn't work :(

avatar image Blankzz · Aug 10, 2011 at 11:38 PM 0
Share

How are you getting the projectile to move in the first place. Are you using forces or setting its position?

avatar image Eirikir · Aug 10, 2011 at 11:50 PM 0
Share

I'm adding a force at the birth of the projectile, which is not constant and letting the physics handle the rest. $$anonymous$$y projectiles are large boulders.

avatar image Blankzz · Aug 11, 2011 at 12:22 AM 0
Share

Ok so the getting the velocity should work fine. Sounds like something is stopping your object. First debug the rigidbodies velocity before and after teleporting to see when the object is changing velocity.

Just a thought try. Setting the rigidbodies position ins$$anonymous$$d of the transforms.

col.rigidbody.position = teleportTo.position;

or

col.rigidbody.$$anonymous$$ovePosition(teleportTo.position);

avatar image Eirikir · Aug 11, 2011 at 12:40 AM 0
Share

Thanks Blankzz, it works now. $$anonymous$$ade the mistake of leaving the collider on one of the exitportals hehe.

Show more comments
avatar image
1

Answer by Unamine · Aug 10, 2011 at 10:36 PM

Create a variable that stores the value of the current speed of the projectile before the teleport, then you use this value in the AddForce rigidbody when it is teleported;)

I hope I have helped ;)

Vote +1 :P

Comment
Add comment · 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
0

Answer by DGArtistsInc · Aug 10, 2011 at 08:50 PM

ok if it has a rigidbody then make a function Update and put the line of script below in it.

 transform.rigidbody.AddForce(transform.forward * speed);

Just make a speed variable after that and it should work.

Comment
Add comment · Show 2 · 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 Owen-Reynolds · Aug 10, 2011 at 09:50 PM 0
Share

I think the hint is to have a rigidbody in the first place. I just tried firing some virtual rockets into a triggerBox that changes the position, and they come out with the same velocity as going in.

avatar image Eirikir · Aug 10, 2011 at 10:20 PM 0
Share

I don't want to add new force to the projectile, just keep the same velocity exiting the second portal as it had entering the first. @Owen, the projectile is already a rigidbody so the problem does not lie there.

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

6 People are following this question.

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

Related Questions

How do you get a moving trigger collider to trigger OnTriggerEnter if the CharacterCollider is not moving? 0 Answers

My instanced projectiles will not trigger the OnTriggerEnter command on enemies 2 Answers

Teleportation Loop issue 1 Answer

Piercing bouncing projectile 1 Answer

my OnTriggerEnter function won't get called 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