Mesh facing the wrong way!

Started by
9 comments, last by Scouting Ninja 6 years, 10 months ago

So i imported my mesh into unity and when it moves it acts like its right side is his front and start walking sideways!

i tried re importing it and i tried making the mesh again but facing it a different way but it doesnt change in the game please help ive been trying to fix it for ages!

 

Advertisement

Unity sucks this way. It has to do with Unity's coordinate, then there is also the fact that it can't import normals correctly, it's scale has problems, it imports smooth groups wrong... In short: there isn't any format, mesh type or 3D software than Unity imports correctly.

So here is what you do: You import your 3D software file, if you use Blender that means importing the .Blend. Remember to delete everything in the scene you don't want to import.

Once you have imported this file you will find it is attached to a container, a empty 3D object. Apply movement to this object instead of the character. The character is attached to this object and will act with it, this object has the correct rotation for Unity.

 

No matter if you use Blender, Maya or Max; Unity will import the mesh as a .FBX, so there is no downside to doing things this way; in performance. Although if you give someone the editor files they also need the same 3D software.

Check that Unity calculates the normals and tangents, instead of importing them. Don't bother with smooth groups, they increase the vertex count, limiting the batching Unity can do with a object.

Always build your material in engine, no matter what engine you use.

 

Importing the 3D software file is only a short term solution, you will need to make the proper adjustments at some point. To do this make a axis in your 3D software and align it with Unity. If you want I can explain more about this.

24 minutes ago, Scouting Ninja said:

Unity sucks this way. It has to do with Unity's coordinate, then there is also the fact that it can't import normals correctly, it's scale has problems, it imports smooth groups wrong... In short: there isn't any format, mesh type or 3D software than Unity imports correctly.

So here is what you do: You import your 3D software file, if you use Blender that means importing the .Blend. Remember to delete everything in the scene you don't want to import.

Once you have imported this file you will find it is attached to a container, a empty 3D object. Apply movement to this object instead of the character. The character is attached to this object and will act with it, this object has the correct rotation for Unity.

 

No matter if you use Blender, Maya or Max; Unity will import the mesh as a .FBX, so there is no downside to doing things this way; in performance. Although if you give someone the editor files they also need the same 3D software.

Check that Unity calculates the normals and tangents, instead of importing them. Don't bother with smooth groups, they increase the vertex count, limiting the batching Unity can do with a object.

Always build your material in engine, no matter what engine you use.

 

Importing the 3D software file is only a short term solution, you will need to make the proper adjustments at some point. To do this make a axis in your 3D software and align it with Unity. If you want I can explain more about this.

 

I imported the file but there was no empty 3D object? i added one but it just went off on its own without the mesh

If you add one you need to drag the mesh into it using the Unity Hierarchy, window with the list of object names, check that both objects are at the 0,0,0 point when doing it.

Once you have them linked this way, drag the object out of the hierarchy into a assets folder to create a prefab for re-use. Check the Unity manual on importing and  the prefabs topics for more details.

 

If you used the 3D software save file, then the object you got is the container. Click on it's arrow in the hierarchy to view what is inside.

10 hours ago, Scouting Ninja said:

If you add one you need to drag the mesh into it using the Unity Hierarchy, window with the list of object names, check that both objects are at the 0,0,0 point when doing it.

Once you have them linked this way, drag the object out of the hierarchy into a assets folder to create a prefab for re-use. Check the Unity manual on importing and  the prefabs topics for more details.

 

If you used the 3D software save file, then the object you got is the container. Click on it's arrow in the hierarchy to view what is inside.

I just tried this it doesnt seem to work i will try and send a video

 

I attached a video below

also what i show in the video isnt the original problem before the monster was upright and just faced his right side towards me 

2017-06-20_09-50-31.mp4

Can you upload a screen of the monster, also we need to see the script to see if the problem isn't there.

This image will show what I am looking for:

 

YIm8Y0p.png

 

2 hours ago, Scouting Ninja said:

Can you upload a screen of the monster, also we need to see the script to see if the problem isn't there.

This image will show what I am looking for:

  Reveal hidden contents

YIm8Y0p.png

There is a screen shot and here are the scripts for he AI


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AIScript : MonoBehaviour {

	public float fpsTargetDistance;
	public float enemyLookDistance;
	public float attackDistance;
	public float enemyMovementSpeed;
	public float damping;
	public Transform fpsTarget;
	Rigidbody theRigidbody;
	Renderer myRender;

	// Use this for initialization
	void Start () {
		myRender = GetComponent<Renderer> ();
		theRigidbody = GetComponent<Rigidbody>();
	}
	
	// Update is called once per frame
	void FixedUpdate () {
		fpsTargetDistance = Vector3.Distance (fpsTarget.position, transform.position);
		if (fpsTargetDistance < enemyLookDistance) {
			myRender.material.color = Color.yellow;
			lookAtPlayer ();
			print ("Look at dah player");
		}
		if (fpsTargetDistance < attackDistance) {
			myRender.material.color = Color.red;
			attackPlease ();
			print ("Attack");
		} else {
			myRender.material.color = Color.blue;
		}
	}

	void lookAtPlayer(){
		Quaternion rotation = Quaternion.LookRotation (fpsTarget.position - transform.position);
		transform.rotation = Quaternion.Slerp (transform.rotation, rotation, Time.deltaTime * damping);
    }

	void attackPlease(){
		theRigidbody.AddForce (transform.forward * enemyMovementSpeed);

	}
}

 

 

Screenshot.png

OK first your monster need to be rotated so that he is looking towards the blue arrow.

Then use the Unity look function instead of your "void look at player" function. That is "transform.LookAt(target)".

https://unity3d.com/learn/tutorials/topics/scripting/look this tutorial explains it.

Blue is forward, red is side ways and green is up.

37 minutes ago, Scouting Ninja said:

OK first your monster need to be rotated so that he is looking towards the blue arrow.

Then use the Unity look function instead of your "void look at player" function. That is "transform.LookAt(target)".

https://unity3d.com/learn/tutorials/topics/scripting/look this tutorial explains it.

Blue is forward, red is side ways and green is up.

Ok but when i rotate the monster and do the script he just walks to his right facing forward? im sorry i think being stupid, i might have done the script wrong can you please edit it the way you explained?

 

This Unity pack has a simple setup for using the navmesh.

Note that waypoints don't need to be set this way, this is only to show how to find the player. https://docs.unity3d.com/Manual/nav-AgentPatrol.html

 

Import the pack by right clicking and selecting custom pack, don't import into your game this is only a reference; there is a lot that can be improved especially my hard coding.

NavMeshHelp.unitypackage

This topic is closed to new replies.

Advertisement