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 alb917 · Apr 27, 2013 at 09:00 PM · iosraycastjumpnormalsoncollisionstay

jump at opposite angle of surface

I am super stuck on making a jumping script for my player. I am creating a kind of "rolling jump' clone (http://arcadelife.wordpress.com/2012/04/22/rolling-jump-review-ipodiphone/) and I want the player to be able to jump on rotating cylinders, and then jump off in the opposite direction of the floor. I have tried to use raycastHit to find the normal of the ground, onCollisionStay, eulerAngles, transformDirection but as I am not very good at coding i'm finding it hard to integrate bits together.

Below is a drawing of what I want to achieve, but with gravity still so if the player jumps towards nothing it will fall to the ground. At the moment I'm using fixed joints to attach the player to the rotating platforms, by creating it on collision.

alt text

Here is my current code:

 private var myNormal: Vector3;
 private var distGround: float;
 private var turnAngle: float = 0;
 
 function Start (){
     myNormal = transform.up;
 }
 
 function Update () {
 
     var up = transform.TransformDirection(Vector3.up);
     var ray : Ray;
     var hit : RaycastHit; 
     Debug.DrawRay(transform.position, -up * 10, Color.green);
     
       var fingerCount = 0;
       for (var touch : Touch in Input.touches) {
           if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
             fingerCount++;
       }
           if (fingerCount > 0){
               
               
               
               
               rigidbody.velocity = Vector3.up * minHeight;
               
             print ("User has " + fingerCount + " finger(s) touching the screen");
             ray = Ray(transform.position, -myNormal);
             
             if (Physics.Raycast(ray, hit)){ // use it to update myNormal and isGrounded
                   isGrounded = hit.distance <= distGround + deltaGround;
                   myNormal = Vector3.Lerp(myNormal, hit.normal, Time.deltaTime);
              }
              var turn = Input.GetAxis("Mouse X") * turnSpeed * Time.deltaTime;
              turnAngle = (turnAngle + turn) % 360;
             var rot = Quaternion.FromToRotation(Vector3.up, myNormal);
              rot *= Quaternion.Euler(0,turnAngle,0); // and to current direction
              transform.rotation = rot;
             
         }
 }



I've looked at many other questions and answers but none of them seem to work for me, does anyone have any ideas or answers? This has been driving me crazy for ages!

Thanks

example.png (11.5 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

2 Replies

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

Answer by alb917 · Apr 29, 2013 at 12:41 PM

I actually managed to solve this by ticking Animate Physics in the animation component! I've literally been stuck on this for a good 2 weeks and it was something so simple!

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 cdrandin · Apr 27, 2013 at 10:57 PM

Here is a script to rotates around the center of your screen. so you have an idea what to do.

Using C#:

 using UnityEngine;
 using System.Collections;

 public class TEST : MonoBehaviour {
 public string stringToEdit = "X";
 public Vector2 center;    
 public float r;
 public float angle;
 
 private float x, y;
 private float incr;
 
 // Use this for initialization
 void Start () {
     center = new Vector2( Screen.width/2, Screen.height/2 );
 
     r = 100.0f;
     angle = 0;
     incr = Mathf.PI/24;
     stringToEdit = "X";
 }
 
 // Update is called once per frame
 void Update () {
     // parameterize the points on the circle as a function of time using the relations 
     // x=cx+rcos(t),y=cy+rsin(t) for (cx,cy) the circle's center, r its radius, 
     // and t the time.

     x = r*Mathf.Cos( angle ) + center.x;
     y = r*Mathf.Sin( angle ) + center.y;

     
     angle += incr;
         if(angle > Mathf.PI*2)
             angle = 0.0f;
 }
 
 void OnGUI() {
     GUI.Label(new Rect(x, y, 100, 50), stringToEdit);
 }
 }
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 cdrandin · Apr 27, 2013 at 10:59 PM 0
Share

SO, if you want to move it with some input just have for every cycle you press left or right you move +/- the incr value which you add onto the angle, to give a rotating effect about the center of your screen.

avatar image alb917 · Apr 28, 2013 at 12:29 AM 0
Share

Sorry, I forgot to say that my platforms already rotate, which I have done with animations. I can jump from platform to platform but when the player jumps there is only movement on the Y axis, even if the player is on the side of the platform.

Thanks for your answer though!

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

12 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

Related Questions

Raycast Hit not working 0 Answers

iPad - camera.ScreenPointToRay always returns the same ray 1 Answer

How to get rotation relative to the ground normal? 0 Answers

How to pick up object on touch? 1 Answer

issues with jumping and linecast2d and raycast2d 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