Jump to content
  • Advertisement

sun113344

Member
  • Content Count

    2
  • Joined

  • Last visited

Community Reputation

0 Neutral

About sun113344

  • Rank
    Newbie

Personal Information

  • Interests
    Programming

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Hi, So earlier I posted this on how to get AI to jump in an arc. But I realised it was probably in the wrong place on this forum. However, I'm not even convinced I'm going about solving this the right way. So I would like to know what techniques I can use to get an AI to jump between to platforms in a 2d game? Currently, I'm using SUVAT physics equations to calculate the arc path between nodes but I'm having difficulties getting my ai to follow the jump path. I can get my ai to follow the jump path using the starting position and using initail velocity I can displace the the ai's position. But this sets the ai's position directly and basically ignores any physics. Ofcourse, I can add some extra code to detect a collision in mid air and stop and apply gravity if there is a collision. But I already have collision detection code but the interface requires setting a the velocity on the object. So my current thought is between: Set ai's position using suvat equation such as: s = ut + (1/2)(a)(t^2). Where I can get the initail velocity and time to target and then simply follow the path and then implement some code to detect collisions while jumping. The path following is really quite smooth. Some how set the velocity of the ai using: v = u + at which ends up with weird movement but allow to reuse some existing code I have. not sure my implementation is even correct here. Use some other better method that I am not aware of. Does any one have any thoughts on this? The code below is what I'm doing while for point 2: IEnumerator Jump(LaunchData launchData) { float timer = 0.0f; while (timer <= launchData.timeToTarget) { velocity.x = launchData.initialVelocity.x + (timer); velocity.y = launchData.initialVelocity.y + (timer * gravity); timer += Time.deltaTime; enemyController.Move(velocity * Time.deltaTime); yield return null; } jumping = false; }
  2. Hi, Currently I'm trying to get my ai enemy path find to the player. I've got astar working as expected but i want the enemy ai to jump at an arc when it need to jump between platforms. Here how I'm calculating initail velocity using suvat physics equations: public LaunchData CalculateLaunchData(Vector3 launchTarget, Vector3 projectilePositions, float height) { float displacementY = launchTarget.y - projectilePositions.y; Vector3 displacementXZ = new Vector3(launchTarget.x - projectilePositions.x, 0, launchTarget.z - projectilePositions.z); float time = Mathf.Sqrt(-2 * height / gravity) + Mathf.Sqrt(2 * (displacementY - height) / gravity); Vector3 velocityY = Vector3.up * Mathf.Sqrt(-2 * gravity * height); Vector3 velocityXZ = displacementXZ / time; return new LaunchData(velocityXZ + velocityY * -Mathf.Sign(gravity), time); } According to the v = u + at formula, I can use time and initail velocity to calculate final. So does final velocity mean velocity at any time t? My idea was todo something like this in my enemy ai class, but it doesnt quite work expected as my enemy is having a weird landing and jumping behaviour and not as smooth as when I just add displacement to original position. Here is what I'm doing: IEnumerator Jump(LaunchData launchData) { float timer = 0.0f; while (timer <= launchData.timeToTarget) { velocity.x = launchData.initialVelocity.x + (timer); velocity.y = launchData.initialVelocity.y + (timer * (ps.gravity)); timer += Time.deltaTime; enemyController.Move(velocity * Time.deltaTime); yield return null; } jumping = false; } Where enemyController will handle some collision detection related stuff and call Transform Translate method in unity. Something else is that I can use the equation: s = ut + (1/2)(a)(t^2) to get the displacement directly. This works quite well as I can just add the displacement directly to the jump starting position. However, I can only set the transform.position directly with this way and thus I can't handle collisions as nicely as transforming with a velocity (since my resusable code is inside the controller takes velocity). I'm quite new to unity and game programming, so am I doing something wrong with setting my velocity? I can add a little gif later to better visulise things.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!