Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 toomaasv · Feb 28, 2014 at 05:29 PM · physicsraycastdetectionfixedupdateisgrounded

detection raycast too late

so i've been trying to use a raycast to detect the collision of my character on ground. I have the isGrounded=Raycast inside fixedUpdate. The detection however, happens every frame and not every physics step?

code:

using UnityEngine; using System.Collections;

public class Movement : MonoBehaviour {

 float direction = 1;
 float speed = 0.01f;
 float jumpHeight = 0.03f;
 float fallSpeed = 0.1f;
 bool isGrounded;
 float velx = 0;
 float vely = 0;
 
 void Update () {
     Move();

 }
 void FixedUpdate(){
     isGrounded = Physics2D.Raycast (transform.position, -Vector2.up,0.13f,~(1<<8));
 }
 void Move(){
     if (velx < -0.1f){
         transform.eulerAngles = new Vector2(0,180);
     }
     if (velx > 0.1f){
         transform.eulerAngles = new Vector2(0,0);
     }
     velx = direction * speed;

     if (isGrounded) {
         vely = 0;
         if (Input.GetButtonDown("Jump")) {
             vely = jumpHeight;
         }
     } else {
         vely -= fallSpeed * Time.deltaTime;
     }
         transform.Translate (new Vector2(velx,vely));
 }

}

any ideas?

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 robertbu · Feb 28, 2014 at 05:32 PM

'transform.Translate()' is not a physics step. You are directly manipulating the transform (teleporting the object to a new location). In addition, Update() can be called more frequently than FixedUpdate(). Moving your Raycast() into Update() should fix the immediate problem.

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 toomaasv · Mar 01, 2014 at 09:26 AM 0
Share

Thank you for the response, but your solution did not work.. I understand that transform.Translate isn't a physics step, but it needs to happen more than every frame, because otherwise it will go through objects. Or it needs to calculate how far it can travel on the last frame before hitting something.

Here's a screenshot of the problem first frame and last frame

untitled.png (7.6 kB)
avatar image
0

Answer by DemonJAZ · Jun 30, 2019 at 05:26 AM

Hi i am facing same issue can you explain how you solved it?

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

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

21 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

Related Questions

Raycast and Physics(Ragdolls): Update() or FixedUpdate()? 1 Answer

IsGrounded Script Not Working 0 Answers

Raycast drags behind the transform that generates it 1 Answer

Multiple raycasts in same fixedupdate 3 Answers

Mouse Input for RayCast - Update or FixedUpdate 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