playMaker

Author Topic: Bullet transform position  (Read 2176 times)

LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 226
Bullet transform position
« on: March 18, 2017, 08:29:59 PM »
Hey guys, i'm trying to recreate this code in playmaker.

I want to fire a bullet and use raycast to register any impact. I store an old position and a new position every frame. The old position is the current position of the bullet and the new position is the position it would reach if the raycast doesn't hit anything.

Quote
Bullet {
    Update {
        newPos += speed * transform.forward * Time.deltaTime;

        direction = newPos - oldPos;
        distance = direction.magnitude;

        if (Raycast(oldPos, direction, distance)) {
            Destroy(gameObject);
        }
        else {
            oldPos = transform.position;
            transform.position = newPos;
        }
    }
}

This is what i have, minus the raycast. I just need to get the bullet working right.
I've already got the distance working.

Speed "Float" == 300 (or any speed)

Get Position == oldPos
------------------------------------------------------------------------------
Get Time Info == time.deltaTime
Float Operator == Speed, time.deltaTime, Multiply = newPos
------------------------------------------------------------------------------
Translate == set to newPos

Math is not really my thing so anybody see the obvious mistakes i'm making?


Ofonna

  • Full Member
  • ***
  • Posts: 230
Re: Bullet transform position
« Reply #1 on: March 20, 2017, 01:46:04 PM »
trying to recopy code can be done but extremely confusing, rather than doing that i would suggest you use your logic to figure it out as playmaker really makes it very easy.

what are you trying to do?

are you trying to shoot a projectile (visible bullet) or just a raycast to represent your bullet


LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 226
Re: Bullet transform position
« Reply #2 on: March 20, 2017, 03:13:57 PM »
I'm trying to shoot an empty gameobject without a rigidbody and i want to get the position of the projectile at the beginning of each frame and then calculate the position it's going to be in at the beginning of the next frame.

And then raycast between the old and the new position.

This way i can detect a collision with objects no matter what speed the bullet is traveling at.

I've already tried various ways, but i need precise collision detection, so this should be the optimal way to do it.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Bullet transform position
« Reply #3 on: March 29, 2017, 04:59:15 AM »
Hi,

Yes, at least the right approach, you might need to fiddle with it, make sure you create some convenient settings to increase range of detection etc, this may come useful during development.

 Bye,

 Jean