playMaker

Author Topic: Help with ball game needed!  (Read 3166 times)

Blue Fire Games

  • Playmaker Newbie
  • *
  • Posts: 4
Help with ball game needed!
« on: May 29, 2013, 01:52:39 PM »
Good day everyone! I'm working on a ball game, where you control the ball, that moves only on X and Y axis'. I'm making it only with a Playmaker, but I've watched some tutorials about making ball games with C# or Java, so i understand the principle of how this works: you simple need to add force to your sphere in direction you need. But when I've made the FSM and added some force to sphere (When you press "A" or "D" it rolls left or right) it rolls good, but it stops REALLY SLOWLY! It even seem to be, that it doesn't stop at all! Please, if somebody knows how to repair this help! Thanx in advance!

izzycoding

  • Playmaker Newbie
  • *
  • Posts: 29
Re: Help with ball game needed!
« Reply #1 on: May 29, 2013, 03:46:04 PM »
Hi,

I am not 100% sure. But how I would set this up would be to put a plane on the ground. Then position the camera to look down on it. Then by adding a rigid body you could apply gravity and drag.
The only change for the controls would be to set the force on X and Z as Y would be the direction of gravity onto the plane under the ball.

Not sure if this helps.

Regards,

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Help with ball game needed!
« Reply #2 on: May 30, 2013, 07:11:42 AM »
Hi,

 it's your lucky day, there is a fully working game done with playmaker for this.

https://hutonggames.fogbugz.com/default.asp?W881

bye,

 Jean

Blue Fire Games

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Help with ball game needed!
« Reply #3 on: May 30, 2013, 07:38:04 AM »
Oh, thanks a lot! It is the best for me at the moment, but it uses the same technology, as I do, so it stops slowly again. Arghhh... I have another script, that I used before:


using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour
{
    private Vector3 inp;
    private Vector3 delta;
    private Vector3 oldPos;
   private Vector3 gravity;
    private const float pi2 = Mathf.PI * Mathf.PI;

    public float diam = 6f;

    public float speed = 6f;

    public Transform cam;
   GameObject fire;

   
   // Use this for initialization
        void Start (){
            oldPos = transform.position;
         Physics.gravity = new Vector3(0, -75, 0);
        }
       
        // Update is called once per frame
        void Update ()
{
   fire = GameObject.Find("fire");
    if (Input.GetButtonDown("Jump")){     
   fire.particleEmitter.emit = true;
   diam = 10f;
    speed = 10f;
    }
    if (Input.GetButtonUp("Jump")){
fire.particleEmitter.emit = false;
       diam = 4f;

    speed = 4f;
    }
            inp.x = Input.GetAxis("Horizontal");
            inp.z = Input.GetAxis("Vertical");
        }
    void FixedUpdate()
      {
         
        Vector3 cp = transform.position - cam.position;
        cp.y = 0f;
        transform.Translate(Quaternion.LookRotation(cp) * inp * speed * Time.deltaTime, Space.World);
        delta = oldPos - transform.position;

        float ang = Mathf.Sin(delta.magnitude / diam / pi2) * Mathf.Rad2Deg;
        transform.RotateAround(Vector3.Cross(delta, Vector3.up), ang);
        oldPos = transform.position;
   
}
}

It is very good in rolling, but have some nasty lags and bugs with speed of rotation of the ball. But this ball game example is great! Thanks a lot again ;)

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Help with ball game needed!
« Reply #4 on: May 30, 2013, 08:15:29 AM »
The ball is going to roll on a flat surface until friction stops it which is a pretty long way. The best you can do is apply force in the other direction.

Here is another example, maybe it will help. Use WASD controls to move the ball.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Blue Fire Games

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Help with ball game needed!
« Reply #5 on: May 31, 2013, 12:25:48 PM »
Thanks to all, guys! But I have one more question: how can I make my ball to jump? I also tried to add some force to it, but the problem is, that you can add force to it anywhere it is (In the air or on the ground), but in real life you can't jump from in the air, you need some ground under your feet :) So my ball now can jump and jump and jump... how can I tell him not to jump in the air?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Help with ball game needed!
« Reply #6 on: May 31, 2013, 01:24:03 PM »
Hi,

 lucky you for a second time :)

 in the same set of game samples, study the platform jumper, basically, It only can jump if its grounded, and character collider do expose this feature. so you simply double check that the ball is indeed grounded, and only if it is, you allow the user to jump.

 If you use a simple sphere collider, simply maintain a FSM that is responsible for watching the collision with the floor, raise a bool to true ONCOLLISIONENTER and lower that bool to false ONCOLLISIONEXIT. Then in your jump behavior, watch or query for that bool value of that FSM, and done.

bye,

 Jean

Blue Fire Games

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Help with ball game needed!
« Reply #7 on: May 31, 2013, 01:34:08 PM »
Hah, thanks Jean! Without you my ball game would be a "Sphere that can do nothing game"! XD