So I have an enemy AI that spawns from various points and follows a way point system. What I am trying to do is capture the movement direction into a variable and say basically if currPos.x or .y is +1 or -1 then apply it to a float in my blend tree.
https://pastebin.pl/view/6ca3d428
I tried originally without a blend tree, using bools but I still cant figure out how to capture into a variable which way something is going. I was able to capture a transform.position.x but that was just monitoring its actual position in xyz on the screen and not a velocity of foward or backwards.
Related
Please is it possible to make a Player with rigidbody or character controller run on wall just like The Flash. Please guide me on how to implement this.Here's a link of what I'm talking about. Thank you in advance.
Rotate the player to be vertical to the building, adjust the gravity parameter on your rigid body (make it lower so the added force won't be canceled by it) and just add the force (or set the velocity, whatever makes you happy)
I'm going to assume you already know how to move the player around on the ground. All you need to do is create some form of detection for when they want to begin running on the wall (maybe the player presses a button, or walks up to the wall), at which point you will want to do 2 things: rotate the player to have their feet on the wall, and change gravity to be pulling the player into the wall.
If we assume the player is facing the wall when they go up on it, you can just rotate 90 degrees backwards. Changing gravity should be easy too. Once the player is fully rotated, do something like this
Vector3 newGravityVector = tranform.down.normalized
Physics.gravity = transform.down.normalized * 9.8 //9.8 is the default gravitaty value, feel free to use a different multiplier if you wish.
(this script should be attached to your player)
I'm trying to make a game using unity and at this point I have created a cube object, a ground object a couple other things. I can make it move by giving it a forward force. I'm basically trying to make a game about a cube that you can navigate through obstacles.
What I want to know is how to get the input like touch input. For example you would use getkey("d") If you wanted to get input from "d" in the keyboard. How would I do the same except for touch input in android?
Use this
Input.GetMouseButtonDown(0)
Example
if(Input.GetMouseButtonDown(0)){
circle.velocity = Vector2.up * jumpForce;
}
https://docs.unity3d.com/ScriptReference/Input.GetTouch.html
You can use this to get a touch object which will give you the screen position, then you can use your cameras position and angle to cast a ray from that point to see if the user is touching the cube.
I'm learning Unity 2D and I want to do something like this:
Basically the character runs into the box/edge and it falls over. BUT! I want to lock down the X axis somehow. So in reality it would kinda look like if it was just rotated simple by 90 degrees (with some kind of acceleration).
I've tried to do it with rigidbody2d and edgecollider and AddForceAtPosition, but I failed miserably.
What I really wanted to do is lock down the "wall" and apply the force at the very top of the rigidbody so it would just fall over to the right, but it simply didn't work out.
Any help would be appreciated!
Remember that same logic applies to physics in games as it does to physics in real life. Just make a hinge and put the anchor and connected anchor at the same location at the bottom and set a limit for hinge.
Wall:
Hinge:
I set Lower Angle to something near 90, otherwise wall becomes uneven when it drops.
Remember to put a Rigidbody2D and a Box Collider for wall.
Firstly, I would lock the rotational axes that you don't want to move on your rigidbody, then, if your object origin is located on the ground / bottom of the object, you can add rotational torque to the object to achieve the affect you want :) http://docs.unity3d.com/ScriptReference/Rigidbody.AddTorque.html
I am making a FPS game, I created a peaceful AI for the moment and when the character is died, I just want it to be oriented according to the normal below it. I show you the result for the moment :
as you can see, the character is flying, because the terrain is not straight.
I am trying (without success) to make something like that :
I have the (x,y,z) coordinates (character position) and the normal to the plane.
Yes the normal is always facing up, as you can see on my drawing, even if I drew it in the good pose. I dont understand when you are talking about the quaternion, which new normal are you talking about ?
I already have the normal of the plane under the character, so, part of the jobs is already done :)
Your character's death pose is always with the normal facing up, right?
And you want to rotate it to another normal.
You can find a Quaternion that represents the rotation between two vectors (up and the new normal) to rotate the mesh.
This question has the answer to that:
Quaternion from two vector pairs
To know the normal of your terrain, you can probably cast a ray down and get the normal from the collision information depending on the physics engine you are using.
Edit:
Some background info:
A quaternion represents a rotation. So what I'm suggesting is that you use the answer from the question I linked to calculate the rotation between the default orientation of the character's death pose (UP) to the new orientation (Terrain Normal)
Then you can just transform your dead character with the Quaternion and it'll follow the terrain's normal.
Here's a sketch: calculate Q from UP and N with the solution from the Link and rotate your character's model with Q:
I'm trying to make a respawn system for a game in unity that starts the character back on the last platform they were on.
As it is currently, it keeps track of which platform they were last grounded on with onCollisionEnter and detects if onCollisionExit touches an out of bounds area.
I need to find the position of a face on the mesh with the y axis (assuming the best way is to do a raycast on the global y axis from the center of the platform) and add the height of the character/2 to determine where to respawn the character.
I'm very new to unity and c#, so I've never done a raycast before and I'm not sure if it's possible to raycast from inside an object to find it's mesh in a given direction, or if there is a better/more efficient way.
Thanks in advance :)
"if it's possible to raycast from inside an object to find it's mesh in a given direction"
You can place a empty gameobject at the center of your mesh (make it child of your mesh ) then pass the position of this empty gameobject to raycast origin.
I usually make re-spawn system with triggers. If you explain little bit more what actually you want to do. I'll try to guide you in that particular direction.