Author Topic: Bullet transform position  (Read 311 times)


  • Junior Playmaker
  • **
  • Posts: 79
    • 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.

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

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

        if (Raycast(oldPos, direction, distance)) {
        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?


  • Full Member
  • ***
  • Posts: 229
    • View Profile
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


  • Junior Playmaker
  • **
  • Posts: 79
    • 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.


  • Administrator
  • Hero Member
  • *****
  • Posts: 12405
  • Official Playmaker Support
    • View Profile
Re: Bullet transform position
« Reply #3 on: March 29, 2017, 01:59:15 AM »

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.




  • Playmaker Newbie
  • *
  • Posts: 21
    • View Profile
Re: Bullet transform position
« Reply #4 on: March 30, 2017, 04:48:24 PM »
I simply created an empty game object as the "aim" point,
had it "Look At" the target, then raycast from there.
This works fine for fast moving projectiles, maybe over thinking things
but it would be nice to figure out a movement prediction that could offset the angle of a slower projectile based upon the targets speed and direction, especially for a large AOE like the plasma weapon in the original DOOM.
May cheat a little bit and if the projectile gets within close distance, then will "lock on" and curve towards them. Later will try along the lines of (Get velocity / Vector Dot) so speed + direction that somehow adjusts the Look At angle... Lol, probably not going to happen.
« Last Edit: March 31, 2017, 12:30:14 AM by jeanfabre »