To be honest that's a bit of a strange concept because preferring cardinal directions would just mean you are always moving cardinally, since any point can be reached that way.Dwayne Yancey and Cardinal News have rendered an invaluable service to the Commonwealth by shining a spotlight on Virginia’s continuing loss of talent to other states. The issue has gained the attention of decision-makers in the State Capitol, and the search for solutions seems to have begun in earnest. (Vector3.MoveTowards(transform.position, targetZaxis, speed * direction.z * ltaTime)).z) Įdit: This does not include a weighted result towards a path that goes in cardinal directions. Transform.position = new Vector3((Vector3.MoveTowards(transform.position, targetXaxis, speed * direction.x * ltaTime)).x, Vector3.MoveTowards does not overshoot so you will not see your vibrating effect from before. Vector3 targetZaxis = new Vector3(,, ) //Here you use Vector3.MoveTowards to make your x position move directly towards the Player's x axis, and your z position directly Vector3 GetOrdinalDirection(Vector3 targetPosition) return ordinalDirection.normalized //normalize the ordinal direction to make sure diagonal speed isn't faster Target = GameObject.Find("Player").GetComponent() ĭirection = GetOrdinalDirection(Target.position) MoveTowardsTargetAxis() I'm also not sure why the formatting is so weird on this, I apologize. To make it easier on myself, any instance where I refer to the "Target" you can think of it as the player, and I have chosen to define your 8 directional movement as "Ordinal directions". Unfortunately this code is untested so let me know if it works. This function is useful because it does not overshoot. I reconstructed what I believe you are trying to do using Vector3.MoveTowards instead. The reason you see the rapid back and forth movement as it tried to align itself to the player's axis is because of overshoot, as you probably guessed. Maybe this is a bit more open-ended than some questions, if this is inappropriate, then I apologize for the format. I am looking to see if any different implementation of the concept could improve the behavior so that this buffer wasn't necessary. Maybe less that the buffer is 0.1f, the real issue to me is that the buffer is needed at all. I am concerned about the 0.1 buffer being needed. Call it a peculiar desire if you want, I would like to see some ideas for how that could be done. That said, I was looking to encourage cardinal movement more than others. At a future implementation, I intend to do that by having a "wall check" which will prevent movement in a given direction if a wall is blocking the path ahead. I would prefer based on how I'm seeing it, that the enemy weights movements in cardinal directions above those in diagonal directions. NewFacing.z += playerPosition.z + 0.1f ? -1 : 0 NewFacing.x = playerPosition.x + 0.1f ? -1 : 0 Vector3 GetUpdatedFacing(Vector3 playerPosition) I coded this as the following: void OnEnable() At that point, the enemy should not move at all on the X axis unless the player changes its own X-position. The idea is that if the enemy is not aligned with the player on the X axis, then the enemy will attempt to rectify by moving on the X axis until the player and enemy object are on the same x axis. I want to make an enemy that constantly tries to be aligned with the player object, but doesn't always move directly toward it, and which only moves in 8 cardinal directions. I am working on a "quick project" to get my feet wet and to put something finished in my projects.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |