Tag Info

New answers tagged

0

First, you need to find which blocks should move move, given a particular clicked cell. You'll probably want to use a floodfill algorithm of some sort for that. Once you have your list of tiles, move them all one after the other before doing anything else. The way I would do that would be to change the move function so that it takes another parameter ...


0

Parent the gun to the player not the camera. The camera movement is changing the transform of the gun. The capsule for the player still tips forward and backwards so parenting it to the player will alleviate the issue. Otherwise you can code a fixed transform that only allows for verticle and horizontal transform change instead of a forward transform change ...


0

You could try and check if the distance between two objects is increasing or decreasing or you can use an infinite raycast and check the object it hits.


7

Ok, that's awkward. My last edit revealed the answer to my problem (that I've been struggling with all day): QGraphicsView casts the camera x/y position to integers... This is the solution: void SceneView::centerOn(const QPointF &pos) { if (mScene) { mScene->setX(int(-(pos.x() - width() / 2))); mScene->setY(int(-(pos.y() - ...


0

To detect the direction that your player is facing you can use transform.forward as a vector3 value .


1

To determine the cone you should create some variables like AttackLength, FieldOfViewAngke and get enemy component to determine enemy position lookDirection = enemyPosition - player.transform.position; lookDirection.y = 0; attackDirection = Vector3.zero; float angle = Vector3.Angle(lookDirection, transform.forward); if (Physics.Raycast(enemyPosition, ...


0

The computer is not aware of what type of object is moving around, whether it is a character walking/running (which you don't want to launch when it hits a ramp) or a car driving (which you would want to launch). Since you said that your character is moving at high velocity, that would explain why it is launching. It is best to think of your character as a ...


0

As pixelmike mentioned, the problem might be that the keydown event executes every x milliseconds while the key is being pressed, and that is what produces the wrong player.facing value. Since you want the player to move in only one direction, the one of the last key pressed (and I guess that you set player.moving.x = false somewhere because the movement ...


0

Disclaimer: Coded in 3D, converted to 2D You could use IEnumerator. Like this: public const float stepDuration = 0.5f; private Coroutine playerMovement; private void Update() { if (playerMovement == null) { if (Input.GetKey(KeyCode.W)) //In general not a good idea to use Input.GetKey; use Input.GetButton instead ...


0

Use the following script it will work well... Animator anim; Rigidbody2D rigid; bool facingRight = true; bool canJump = true; public Transform startpos, endpos; public LayerMask groundLayer; void Start() { rigid = gameObject.GetComponent<Rigidbody2D>(); anim = gameObject.GetComponent<Animator>(); } void Update() { float move = ...


2

Here is a simplified example of how you could implement a check to see if your gameObject is grounded or not. It is not perfect, but should probably work for your situation: bool Grounded; void OnCollisionStay2D(Collision2D collider) { CheckIfGrounded (); } void OnCollisionExit2D(Collision2D collider) { Grounded = false; } private void ...


0

Use transform.forward instead of Vector3.forward


2

Scalar multiplication. Assuming the plane moves at constant speed, you can determine how far along it is (0 meaning at departure_point and 1 meaning at arrival_point) progress = distance / speed * time_elapsed You can also compute a vector (x,y) representing the translation of the airplane from its departure point to its arrival point, by subtracting one ...


1

I had the reciprocal of what I should have been using. The math.h class's sin and cos function want the arguments in radians and m_ShipAngle is in Degrees. I was doing movementX = m_ShipVel * (cos(m_ShipAngle * 180 / PI)); movementY = m_ShipVel * (sin(m_ShipAngle * 180 / PI)); When I should have been doing: movementX = m_ShipVel * ...


0

Okay I went ahead and separated my mouse look function which I used to rotate my camera rig, into the X and Y axis and placed them on two different objects. The one with the x axis was used to dictate how what direction my character moves.


1

Use physics instead to move your object like rigidbody.AddForce(Vector3). Using physics will solve your problem with bouncing.


0

Based on the comments above, the followed object "Current" is only moving in FixedUpdate. By default, FixedUpdate runs 50 times per second. In-between FixedUpdates, Unity renders as many frames as it can, each time calling Update, LateUpdate, etc. Because the rendered framerate is usually not a perfect multiple of the FixedUpdate rate, this can cause a ...


0

As Shiro mentioned in the comments, you only move the enemy every half second. Instead you've got to set the direction every half second rather than moving it in a random direction, and make sure it always moves in the direction. And please use a switch rather than such a chain of if else's :)


0

From what you have posted I have a few pointers: There are some Follow scripts you can try to tinker with in the standard assets: **Standard Assets\Utility** and **Standard Assets\2D** You shouldn't have Find functions inside Update() loops as it might slow down your game. Here is how your code can include that: (not the solution just an improvement) ...


1

You can use Vector3.Lerp(transform.position, WAYPOINT POS, Time.deltaTime) for smooth movement from one point to another.


0

The only possibility based on your snippet would be all the collection iterations it has to do each line to find stuff. If you have a lot of objects to hunt through, maybe that could influence performance to cause the stutter although I doubt it. Have you profiled the code to see if it's a garbage collection issue somewhere other than this snippet? Are you ...


2

Based on my memories and for example this: While it's difficult to understand the complicated ANDs and ORs, it seems clear that you forgot to check for the jumpButton being pressed after the other buttons. With leftButton and rightButton, you have Gdx.input.isTouched(0) as well as Gdx.input.isTouched(1) (with OR inbetween them, so I take that as you're ...



Top 50 recent answers are included