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 Wesley21spelde · Mar 03 at 10:57 AM · raycastikplacementfoot

Foot_IK Problems (Foot Placement Raycast

hi guys i have a question aboute this IK system i did follow a tutorial for this script but i am running in to a problem The IK Works but not correct i added a Debug.Draw so can see where the ray`s are and i seems that the Ik only works when the hit.transform.tag == "Walkable" hits the middle of the raycast so i basicaly starts the Ik on my players knee when it hits the tagged object does enyone know a sollution like am other offset or somthing? here is the script


 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Foot_Ik : MonoBehaviour
 {
 
     public Animator anim;
     
     public LayerMask layerMask; // Select all layers that foot placement applies to.
 
     [Range(0, 1f)]
     public float DistanceToGround; // Distance from where the foot transform is to the lowest possible position of the foot.
 
    
     private void Start()
     {
         
         anim = GetComponent<Animator>();
 
     }
 
     private void Update()
     {
 
         if (Input.GetKeyDown(KeyCode.M))
             anim.SetBool("Walk", !anim.GetBool("Walk"));
 
     }
 
     public void OnAnimatorIK(int layerIndex)
     {
 
         if (anim)
         { // Only carry out the following code if there is an Animator set.
 
             // Set the weights of left and right feet to the current value defined by the curve in our animations.
             anim.SetIKPositionWeight(AvatarIKGoal.LeftFoot, anim.GetFloat("IKLeftFootWeight"));
             anim.SetIKRotationWeight(AvatarIKGoal.LeftFoot, anim.GetFloat("IKLeftFootWeight"));
             anim.SetIKPositionWeight(AvatarIKGoal.RightFoot, anim.GetFloat("IKRightFootWeight"));
             anim.SetIKRotationWeight(AvatarIKGoal.RightFoot, anim.GetFloat("IKRightFootWeight"));
 
             // Left Foot
             // We cast our ray from above the foot in case the current terrain/floor is above the foot position.
             Ray ray = new Ray(anim.GetIKPosition(AvatarIKGoal.LeftFoot) + Vector3.up, Vector3.down);
            
             if (Physics.Raycast(ray, out RaycastHit hit, DistanceToGround + 1f, layerMask))
             {
 
                 Debug.DrawRay(anim.GetIKPosition(AvatarIKGoal.LeftFoot) + Vector3.up, Vector3.down, Color.green);
                 // We're only concerned with objects that are tagged as "Walkable"
                 if (hit.transform.tag == "Walkable")
                 {
                     
                     Debug.Log("raycast");
                     Vector3 footPosition = hit.point; // The target foot position is where the raycast hit a walkable object...
                     footPosition.y += DistanceToGround; // ... taking account the distance to the ground we added above.
                     anim.SetIKPosition(AvatarIKGoal.LeftFoot, footPosition);
                     anim.SetIKRotation(AvatarIKGoal.LeftFoot, Quaternion.LookRotation(transform.forward, hit.normal));
                     Debug.Log("we did send out a raycast Left Foot");
                     print("Hit");
 
                 }
                 
 
             }
 
             // Right Foot
             ray = new Ray(anim.GetIKPosition(AvatarIKGoal.RightFoot) + Vector3.up, Vector3.down);
             if (Physics.Raycast(ray, out hit, DistanceToGround + 1f, layerMask))
             {
                 Debug.DrawRay(anim.GetIKPosition(AvatarIKGoal.RightFoot) + Vector3.up, Vector3.down, Color.blue);
                 if (hit.transform.tag == "Walkable")
                 {
                    
                     Vector3 footPosition = hit.point;
                     footPosition.y += DistanceToGround;
                     anim.SetIKPosition(AvatarIKGoal.RightFoot, footPosition);
                     anim.SetIKRotation(AvatarIKGoal.RightFoot, Quaternion.LookRotation(transform.forward, hit.normal));
                     Debug.Log("we did send out a raycast Right Foot");
                     print("Hit");
 
                 }
                 
 
             }
 
 
         }
 
     }
 
 }

alt text

naamloos-3.jpg (252.7 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

0 Replies

· Add your reply
  • Sort: 

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

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

Set Quaternion to another Quaternion, but oriented along 1 Answer

Player Foot IK with Ball 1 Answer

Problem with scripts ignoring my variables/functions? 0 Answers

Terrain collider not following hills when raycasting 1 Answer

Instantiate an object at hit position without it intersecting anything 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