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 /
  • Help Room /
avatar image
0
Question by Unidesky · Jan 28, 2016 at 11:28 PM · 3djumpplatformbounce

Help me with a bouncing platform for a 3d game

Hello, i've been doing a game based on the roll-a-ball tutorial and i want to create piston-like platforms so when the player touch any it will push the ball up to another floor, all the answers and tutorials i've found are for 2d and the script doesn't seem to work the same.

Any idea?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Trigary · Jan 29, 2016 at 04:24 PM

When the piston collides (see: OnCollisionEnter) with the ball, the piston's velocity should change, either by setting the "transform.velocity" to a Vector3 pointing upwards or by adding a force to it (AddForce).

A script attached to the piston should contain something like this:

 void OnCollisionEnter(Collision collidedWithThis) {
      if (collidedWithThis.transform.name == "Ball") {
          transform.velocity = transform.up * speed; //speed is a number variable
      }
 }

But keep in mind, this is just an example and I did not test it, look for tutorials, they will teach you the basics. And 3D and 2D are almost the same, this stuff is very basic, one more axis will just make things look more complicated, but they are almost the same in this level.

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 Unidesky · Jan 30, 2016 at 03:20 AM

Thanks for the tip, i'm trying it now and keeps telling me:

Assets/Scripts/jumpPlatform.cs(12,23): error CS1061: Type UnityEngine.Transform' does not contain a definition for velocity' and no extension method velocity' of type UnityEngine.Transform' could be found (are you missing a using directive or an assembly reference?)

Granted, i'm not the greastest coder in the genre, in fact i copy/paste the piece of code you passed me over a new script and this happened. Also i started trying with other codes from examples of 2d jump scripts and nothing yet, i've look at the oncollision and ontrigger examples of the scripting api and i don't know how to mix them properly.

Again, any ideas?

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 Trigary · Jan 30, 2016 at 07:23 AM 1
Share

Okay, that's me being an idiot, transforms (the things which only have a coordinate in space) don't have velocities. Rigidbodies have velocities:

Below $$anonymous$$onoBehaviour write this:

 private Rigidbody rigid; //this will enable you to access the rigidbody anywhere in your script

In the start "section":

 rigid = transform.GetComponent<Rigidbody> (); //This will set the rigid variable to the Rigidbody attached to the transform of this script

And then:

 rigid.velocity = transform.up * speed;



avatar image Unidesky Trigary · Feb 04, 2016 at 05:00 AM 0
Share

Thanks, i've made a script from parts from this and others and now i have a functional script for bouncing platforms:

 using UnityEngine;
 using System.Collections;
 
 public class jumpPlatform : $$anonymous$$onoBehaviour
 {
     public float speed = 5f;
     public Rigidbody rigidPlayer;
 
     private Rigidbody rigid;
 
     void Start ()
     {
         rigid = transform.GetComponent<Rigidbody>();
     }
 
     void OnCollisionEnter(Collision collidedWithThis)
     {
         if (collidedWithThis.transform.tag == "Player")
         {
             rigidPlayer.velocity = transform.up * speed;
         }
     }
 }

And i have removed the rigidbody from the platform as well. All you have to do is put the script in the platform object and the player object in the rigidPlayer part on the platform (prefab or each one) to make it work.

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

43 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 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

Can someone help me with why my jump wont work properly 0 Answers

Why does my player weirdly clip into environment when jumping? 0 Answers

How do I make my Character Jump? 1 Answer

Make my Cube jump? 1 Answer

How to make a simple jump script in 3D C# 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