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 FrosTech · Aug 16, 2014 at 07:25 AM · c#androidmechanics

Make a player jump when he jumps on a spring!!

Hi there!

I have a prop gameobject "Spring" with a box collider set to triger.

So, whenever player jumps over the spring, he gets lifted in the direction the spring is facing.

You can have the images for the mechanics of the props.

The above image shows the first mechanic. Player jumps over the spring, and he gets thrown upward.

Note: This upward direction is what I want. That is, the spring can be rotated in like left, right, up, and down direction.

I want the spring to throw the player in the direction it is facing the arrow. And, yeah, it includes diagonal push or throw. The picture below shows just that!

Now, I am not saying I can't do this simple problem.

I do have a solution to the problem i.e. The player already has character controller attached to it. Now, When player jumps on the trigger, the spring will add jumpSpeed to the playerController Script that controls the Charactercontroller.

Easily said, right?? That solution is for upward direction. But I also want downward, left, right, diagonal, etc. And, that through the character controller is hell!!

Complexity will rise when I tell that the Enemy AI can also use this spring. Now complexity goes sky high.


I was thinking the solution to be a better one. All I want is that the Spring applies a force or velocity on the Enemy or the player in the direction I specify it through vector3 mostly.

So, force should be able to do that, right??

Thing is, I do not know that!!!

So, any suggestions guyz!

Note: Game is being developed under Unity 3.5.7f6 Windows for Android.

Thank you for your support!!

[1]: /storage/temp/31004-case+1+-+state+3.png

[2]: /storage/temp/31003-case+2+-+state+1.png

case 2 - state 1.png (18.3 kB)
case 1 - state 3.png (12.2 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
1
Best Answer

Answer by Alessio89 · Aug 16, 2014 at 11:27 AM

You have many choices. I'll explain the two more obvious.

1) Use the UP vector of the spring When the player enters the trigger and press the jump key, just get the LOCAL up vector for the spring like this:

Vector3 springUp = SpringObject.transform.up

That way you can rotate the spring and still get the correct Up vector of the spring, then apply a force to the player equals to that up vector multiplied by the magnitude of the force.

2) Expose a Vector3 property in the inspector of the Spring You could also use a public Vector3 field and set it in the inspector. You then apply that vector as force when the player is in the trigger. This way you can tweak the direction and intensity of the force for each individual spring (some may be more bouncy than other?)

Hope that's what you wanted. If not, just be more specific and I'll try to answer :)

Oh, to apply a force you need a rigidbody attached to the entity and then through script use rigidbody.AddForce or rigidbody.AddExplosionForce.

Comment
Add comment · Show 3 · 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 FrosTech · Aug 17, 2014 at 04:45 AM 0
Share

Thanks for the answer, just what I wanted to know about!

I'll let you know how it went later !!

avatar image Alessio89 · Aug 17, 2014 at 01:20 PM 0
Share

Did you figure it out? If you need any more help, just ask :)

avatar image FrosTech · Aug 19, 2014 at 04:20 AM 0
Share

Yes, I did figure it out. I first was using CharacterController, so rigidbody had conflicts with this approach.

So, I prototyped only with rigidBody and it worked well.

But, I was to use CharacterController strictly, so I had to rollback all that, and make custom script looking at your suggestions to create my own AddForcer() simulation using vectors.

Also, do check in on this issue! $$anonymous$$aybe you can help me on this!!

I'm using Unity 3.5.7f6 x86 on Windows 8.

Issue Anisprite animation from OnTriggerEnter()

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

22 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 avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

How to share the post to internet from game in unity3d? 0 Answers

calling java method from unity c# 1 Answer

About ListItems in Unity3D 1 Answer

How to Display high score using GUIText 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