Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Anyone good at Unity and Quaternions/rotations willing to help me out with my Jam game?

A topic by CraigsArcade created Jan 18, 2020 Views: 271 Replies: 7
Viewing posts 1 to 5

If this sort of post isn't allowed feel free to remove it.

It's my first ever Jam and i'm struggling to get my character to rotate correctly the way my game is setup and i can't seem to find a solution to my exact problem on google and it might be helpful to do it over discord if anyone is willing to help a brother out.

My discord is Dreckly#3291 , I'm an amateur artist and programmer and would be willing to do a couple models or something for future jams in return :)

Submitted

Can you post a screenshot of your code and a better description of the problem? I would guess you're rotating your player relative to the wrong space. There are two options for making a rotation happen, one is world space and one is self space. Here's the page in the unity manual : https://docs.unity3d.com/ScriptReference/Space.html


I can help a little more if you post some screenshots and a better description of what you're trying to do, and what's actually happening. :)

I know it sounds silly but I'm not comfortable posting the art for the game yet, i know its irrelevant for game jams but i just prefer it that way.

So i mocked up a 2D image of my problem instead. Although my game is 3D, it's orthographic and fixed camera angle. The way my movement is set up is you can click any adjacent tiles to the player and the player will move to that tile using

transform.position = Vector3.Lerp(transform.position, destinationTile.position + new Vector3(0,1,0), 3f * Time.deltaTime);

That works fine, my problem is i can't seem to figure out how to get the character to rotate when turning a corner, eg always facing in the direction of movement. Iv'e tried a few different bits of code iv'e found online, so far the below code is closest to working, although it appears i need to somehow add an offset to X and Y by 90 degrees because the character rotates but appears to be on a different angle.

Vector3 targetRot = destinationTile.position - transform.position;
Vector3 newRot = Vector3.RotateTowards(transform.forward, targetRot, 1 * Time.deltaTime,0.0f);
transform.rotation = Quaternion.LookRotation(newRot);

Appreciate the help and hope this sort of thing is ok for this group.



Submitted

You usually can't apply quaternions directly and it's usually a bad idea to try and do so.

If you want to modify the object's rotation directly best suggestion I have is to modify the eulerAngles. It's much easier to use as it's just a Vector3.

For example something like:

transform.eulerAngles = Quaternion.LookRotation(newRot).eulerAngles;

I haven't tested the above code but I've got something similar running in my game.

Hope this helps

Thank's for the reply.

That's currently doing the exact same thing as the other, i still need to add offsets , does it make it easier to add them with euLerAngles?, i just can't figure out where to put it in there.

Submitted

eulerAngles is best for setting direct rotations values (It works the same as setting an objects rotation in editer). Other things you could try would be transform.Rotate(x,y,z) for continues rotation or transform.LookAt(targetposition) to point the object towards a location.

Submitted

Pretty much exactly what VISE said, you generally don't want to fuck with Quaternions if it can be avoided. If you're still having problems rotating with Euler angles you could also try making your 3d model a child of the actual player gameobject. That way you can just rotate the 3d model to face the proper direction when needed and you don't need to worry about rotating the actual player gameobject. This should save you some headaches if movement code and rotation code are conflicting in someway. Hope this helps. good luck! 

Thanks for the reply, i think i've left it too late now either way,  barely got 1 level finished without sfx or character rotations but ill figure this stuff out in time for future projects thanks