playMaker

Author Topic: Bullet transform position  (Read 68 times)

LordHorusNL

  • Playmaker Newbie
  • *
  • Posts: 19
    • View Profile
Bullet transform position
« on: March 18, 2017, 05: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?


Carmichael

  • Junior Playmaker
  • **
  • Posts: 65
    • View Profile
    • Email
Re: Bullet transform position
« Reply #1 on: March 20, 2017, 10:46:04 AM »
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

  • Playmaker Newbie
  • *
  • Posts: 19
    • View Profile
Re: Bullet transform position
« Reply #2 on: March 20, 2017, 12: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: 11404
    • View Profile
    • Email
Re: Bullet transform position
« Reply #3 on: Today at 01: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