Is it possible to move 2D character at a specific angle? - c#

I have started developing 2D isometric game in Unity, but i'm struggling with the movement. I want to move my character at a specific angle. To be more specific with you and give you better idea what i like to achieve is to create movement like in "Bouncy Bits"
Here is a video of their gameplay: https://www.youtube.com/watch?v=A6xA4RzuRcM&t=19s
I would love to achieve that kind of moving to my player including him to move forward alone in that same angle without me pressing any keys.
Would really appreciate if someone could help me out, by giving me a code or explain me what i exactly need to do.

Move your character on vector.forward, which is equivalent of (0, 0, 1) on the Z axis. Put your camera on that front angle how they have it. It would look the same.

Related

Unity Rotation Issue - Character Feet look towards movement direction

My question seems simple but I am also very simple and cannot figure this out. The thing is, I´ve got an IK system for the Character's legs. I need the character's feet to "look" in the movement direction.
If I do this: rightLegCurrentRotation = Quaternion.Euler(-transform.up);
The Character´s feet "look" flat down, just as I want, however, if I use the movement direction and do anything but fall down (Since that gives me the same value as -transform.up) the feet´s rotation completely goes wild and makes no sense.
Not sure if I´m explaining myself but essentially what I need is the player's feet to lay flat towards the given direction, kind of like this.
Please let me know if I don´t make sense, quaternions are a real pain and I hardly understand what I´m doing. I am in dire need of help.

Unity3D: How to make an object always touch the map mesh?

i am developing a racing game. But it's not your usual racing game, the bike is supposted to always have the Y coordinate of the same value as the closest point on the map mesh, in other words it is ALWAYS touching it.
What i do not want is the Y coordinate to be dependent upon the X and Y position, as there will be 2 (or maybe more floors).
I have absolutely no idea how to implement this. Completly zero. I am rather new to scripting, and this i way out of my league, i don't even know how to start... The map is not a simple plane, so simple maths won't help.
I'll apreaciate any help at all, not necessarily a solution.
Thanks in advance
This idea is an adapted version of #LeoBartkus's
I suggest using 2 raycasts from the bottom of the bike's wheels and using the 2 hits to position and rotate the bike. This allows for an accurate positioning of the bike for all kinds of terrain, except for spikes narrow and tall enough to appear to pierce the bike. Using a single raycast from the bike's center might cause problems if the ground is uneven, like a crater for example

Objects having same distance/radius from the center (camera) in Unity 3D

It's a 360 Video application on Unity 3D.
I want to place several objects around the camera (which has a fixed position), but I need this objects to have the same distance (same radius) from the Camera (which is the center). How can I do this? Either on Editor or by code.
I have been manually displacing objects around the camera, by dragging them by arrow tool. But it's as inaccurate as a pain to do. :)
Any light on this would help me a lot! Not only me, but anyone working with 360 videos in Unity.
Thank you all in advance!
To solve your problem, an easy solution would be to add a child "child_of_camera" to your camera and then add a child "child_of_child" to the "child_of_camera".
Now that you've done this, move the "child_of_child" away to however far from the camera you'd like it to be. After this, apply the random rotation you'd like to "child_of_camera".
Duplicate "child_of_camera" to however many objects you'd like on screen and then rotate them all to your preference.
Now, when you're moving around the camera, these children will follow along with the camera.
If you're looking so that the rotation of the camera doesn't affect the objects there are two ways you can handle this:
Place camera and "child_of_camera" (this name would now be misleading and should be renamed) under an empty GameObject and move "empty_GO" on the X,Y,Z axis instead of the camera.
or
Create a quick script to attach onto "child_of_camera" so that it always sets the "child_of_camera"s world space rotation to Vector3.zero.
As I stated in the comments, this solution is most likely not the optimal way to fix your problem but it is definitely a very simple solution that is easy to understand and implement. I hope it helps.

Aiming towards thumbstick XNA

currently having some fun in XNA programming a topdown shooter towards the XBox-controller but I'm having some issues right now.
So I move my character with the left thumbstick and aim with my right, so essentially I can move in any direction and still shoot in 360 angle. What I have right now works, but it's very sensitive and "tacky", it likes to stick a bit extra on all the 90 angles before it moves on to the next angle if I'm moving the thumbstick in a perfect outer circle.
So this is what I have right now:
direction.X = gpState_new.ThumbSticks.Right.X;
direction.Y = gpState_new.ThumbSticks.Right.Y;
rotation = Math.Atan2(direction.Y, direction.X);
And then when I draw the player I use rotation as the angle of which I'm drawing it.
Do you got any tips on how to do this better ?
Fredrik
It looks like this is because of the "deadzone" on the stick. The basic fix is probably something like is to use GamePadDeadZone.Circular. Perhaps before your code, something like
GamePadState gpSTate_new = GamePad.GetState(playerIndex, GamePadDeadZone.Circular);
A very similar question was asked on GameDev (and you can see a more detailed answer there), which you might have better luck on with this kinds of questions in the future.

Collision depending of side of the rectangle?

Im not intrested in the code for this problem i just want to be pointed in the right direction.
Im using C# XNA if that helps.
Basicaly for my game i am adding collisions for example the player can't walk or fall through stones.. I have the rectangle and i know i use the .intersects comand but would i need to check collision depending on the side of the rectangle here?
I know if the player is falling i can make if playerRectangle intersects stoneRectangle playerY = stopFalling..
But if the rectangle is coliding on the side of the player.. That would be different wouldn't it ?
One simple way of dealing with this is to work out the main axis of penetration, i.e. is the player further into the rectangle horizontally, or vertically. Then, using this information, you'd move the player so they were just touching the rectangle.
i.e. Player bumps into a wall on his right.
Main axis is Horizontal, and he's to the left of the centre of the rectangle, so we know to move him left.
Searching on gamedev.stackexchange.com will give you lots of different collision detection/response options.
If your game is 2D I would recommend using something like FarSeer Physics rather than implementing yourself.
If you are interested in the algorithms it is open source and you can poke around the code to see how they implemented collision detection.

Categories

Resources