playMaker

Author Topic: Sports Game  (Read 2917 times)

4arrancho

  • Playmaker Newbie
  • *
  • Posts: 27
Sports Game
« on: December 18, 2013, 01:33:53 PM »
Hi

I'm trying to make a sports game, but i'm just in the beggining.
I know it's a hard project for a newbie but i have no hurry...

I've read some parts of Mat Buckland "Programming Game AI by Example" and Thiago Viana "creating a soccer game" but most of it i don't understand cause it's C++ and js.

In my project i have 2 Goal's, Ball, Team A (empty gameobject) with 1 goalkeeper and 4 players (childs), Team B, Floor.

First of all i want to make a project where we don't have characther controller. It's all AI.

1ยบ Goal: How to controll the ball and how to pass it?

player:

"itween move to"
transform position: ball

and then how to attach the ball when in controll by the player? I already tried "collision enter" (seems that it starts too soon)and "parent" but with no success. I also tried other actions but no luck.

Can You help me?

Thanks

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sports Game
« Reply #1 on: December 18, 2013, 03:00:24 PM »
Hi,

I would treat the ball as a physics gameObject, and it would then a matter of adding force to it for kicks.

-- trigger enter is the right approach yes, this will help your player to catch the ball. you can either have your player doing this, or the ball. you then have two possibilities, either you keep adding force while the player is moving, so the ball sticks to the player because you are making it move in the direction of the player ( like in real by kicking it from time to time when it enters again the player's trigger), or by simply turning its physics off using "is kinematic" and attaching the ball to the player ( less realistice, but may be easier as a first step).

Bye,

 Jean

4arrancho

  • Playmaker Newbie
  • *
  • Posts: 27
Re: Sports Game
« Reply #2 on: December 20, 2013, 06:38:04 PM »
Hi again

I still couldn't do it the right way...

If i check the trigger box on the player/ball inspector they "fall in space", so i can't use the "trigger enter" event.

Should the ball and the player have rigidbody? I have in both. The player is a capsule and the ball a sphere.

Thanks and sorry for being so newbie

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sports Game
« Reply #3 on: December 21, 2013, 05:11:28 AM »
Hi,

 Can you get back to me on this after xmas? I'll have a closer look. I remember I did a sample with a player kicking a ball on this forum, but I can't find it right now.

bye,

 Jean

4arrancho

  • Playmaker Newbie
  • *
  • Posts: 27
Re: Sports Game
« Reply #4 on: December 21, 2013, 06:47:03 AM »
Hi, thanks for reply

Off course you can, after xmas i'll ask again.

In the meantime i'll try to make some AI for the players withouth the ball.

If anyone else besides Jean have ideas post them here please

Thanks

4arrancho

  • Playmaker Newbie
  • *
  • Posts: 27
Re: Sports Game
« Reply #5 on: December 22, 2014, 11:43:30 PM »
I'm trying to comeback to this project.

Back to basics

I'ts a 2D scene from top view, so no gravity...

I have: a ball sprite with rigidbody 2D and circle collider 2D;
the player sprite with rigidbody 2D and box collider 2D;

The player has "get axis" for the movement combined with "set velocity 2D"

The ball has "set collision 2D Event" so it knows when it's touched by the player.

Now i don't know how to fix the ball to the front of the player and how to shoot or pass it.

I tried many actions but i can't find the right ones!

Can someone help me?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sports Game
« Reply #6 on: January 19, 2015, 02:12:31 AM »
Hi,

To fix the ball, you can simply use a distance joint, have you tried that? remove any gravity effect and it should be pretty close to sticking to your player.

the other solution is to simply parent the ball to the player and disabe physics on the ball while attached to the player.

To Kick the ball, you need to know the direction and force, and use AddForce2d or SetVelocity2d, that's all you need to have the ball kicked.

Now, to pass it going to be a lot more tricky, typically, I would simply kick on the right direction, then the other player would simply catch the ball using triggers.

 Bye,

 Jean