playMaker

Author Topic: Need to create weapon accuracy  (Read 690 times)

Krauser1129

  • Playmaker Newbie
  • *
  • Posts: 22
Need to create weapon accuracy
« on: August 26, 2020, 04:36:30 AM »
So I have it set up to spawn a bullet that throws itself forward when left click is pressed. I want to add a random rotation that's a variable to the bullet when it's spawned to simulate accuracy. Do I have the FSM on the bullet tell it to have a random rotation once it spawns or is there a different way to do it on the gun FSM itself, right after or before Create Object?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 6957
    • jinxtergames
Re: Need to create weapon accuracy
« Reply #1 on: August 26, 2020, 05:47:54 AM »
Hi.
Both can work, but personally i would prefer the gun to handle it.
When you Create the bullet store it in a variable.
Then parent it to the tip of the gun
Then set rotation and position to 0,0,0
The bullet should point forward from the gun, if not adjust the bullet prefab mesh/sprite.

is the game 2d or 3d?

You can use for example a random float (or 2 random floats when 3D) and use those to set the rotation.

Then for 2D use 'Set Forward Velocity' and for 3d use Set Velocity and set Space to Self.

Btw for bullets its best to use pooling instead of create/destroy.

Krauser1129

  • Playmaker Newbie
  • *
  • Posts: 22
Re: Need to create weapon accuracy
« Reply #2 on: August 28, 2020, 11:12:08 PM »
@djaydino
So I just go Create object, store it as a variable, then do random rotate with a range to the variable that is my object, and it'll spawn it? And thanks so much for answering so quickly!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 6957
    • jinxtergames
Re: Need to create weapon accuracy
« Reply #3 on: August 29, 2020, 12:51:20 AM »
Hi.
Create object will spawn it.
Then position it to where you want it.
Then do velocity.

if you want constant speed, set drag to 0 on the rigidbody.

Krauser1129

  • Playmaker Newbie
  • *
  • Posts: 22
Re: Need to create weapon accuracy
« Reply #4 on: August 29, 2020, 01:34:14 AM »
I'm aware of the velocity, but I'm unsure how to exactly use random rotate. Would you mind explaining it real fast? Do I do create object first, store as variable then do the random rotation?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 6957
    • jinxtergames
Re: Need to create weapon accuracy
« Reply #5 on: August 29, 2020, 05:29:32 AM »
Hi.

Here are 2 samples (for 2D and 3D)




Krauser1129

  • Playmaker Newbie
  • *
  • Posts: 22
Re: Need to create weapon accuracy
« Reply #6 on: August 29, 2020, 06:51:23 AM »
Is there any way to pause these? lol

Krauser1129

  • Playmaker Newbie
  • *
  • Posts: 22
Re: Need to create weapon accuracy
« Reply #7 on: August 29, 2020, 06:53:22 AM »
Holy crap, thank you so much! This is amazing! This solves so many issues for me!