Unity gizmos

Hi I am currently doing a Unity course on Udemy and I have copied the lecturer’s code but the gizmo is not showing.

Here is my code:

private void OnDrawGizmos(){

if(_damageCasterCollider == null){

      _damageCasterCollider = GetComponent<Collider>();

      RaycastHit hit;

      Vector3 originalPos = transform.position + (-_damageCasterCollider.bounds.extents.z) * transform.forward;

      bool hasHit = Physics.BoxCast(originalPos, _damageCasterCollider.bounds.extents / 2, transform.forward, out hit, transform.rotation, _damageCasterCollider.bounds.extents.z, 1 << 6);

      if(hasHit){

        Gizmos.color = Color.yellow;

        Gizmos.DrawWireSphere(hit.point, 0.4f);

      }

}

}

I wonder if anything is wrong with it. I think it could be to do with the position shown of my player:

As you can see the transform is set from the lights rather than the player, however I’m not sure how to change this without moving the entire mesh etc. I just want to move the origin of transforn elsehwere.

Hi 3surr,

For which course is this? What’s the name of the course? And in which lecture are you?

This is not a course associated with the gamedev community I just wanted a bit of help if that’s okay?

Sure. However, we teaching assistants provide support for GameDev.tv’s courses only, and we very likely won’t be able to help you with this problem. The best would be to ask the creator of the course in which you are enroled because they know their content best. If you do not get any help here or over on Udemy, please feel free to ask our helpful community of students over on our Discord chat server. Good luck! :slight_smile:

That is a problem. Your player model is no longer near its own origin. The position shown is where your player is in the world. Your model has moved away from it. You need to figure out why your model is moving away from its origin. It could be root motion of the animation, or it could be that the movement script is acting on the model instead of the whole game object.

Is there a way to solve it?

Yes, you need to figure out why it’s happening and then make it not happen. Like I mentioned, there could be several reasons why it’s moving away from it’s origin. Sometimes it is because there’s a rigidbody on the model and all the collisions are pushing the rigidbody around, but it does not affect the parent. So, the model moves around but the parent does not. The same can happen with root motion on the animation. The animation moves the model, but the parent object is not affected by the animation, so it stays where it is. Sometimes we just overlook something and put a movement script on the model instead of the root object and then, when we move the transform of the script, it moves the model - because that’s where the script is.

I usually avoid root motion on animations because I have very little experience with it and the experience I do have has always caused me headaches (like the situation I mentioned above). As for the others; the rigidbody or movement script should be on the root object, not the model. The model is purely a visual.

I also have no idea what the course is you are doing and how it is doing anything, so I am answering based on my experience with these sorts of issues.

Just fixed it. Appreciate your help fella.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms