YesNoOk
avatar

Changing child helper velocity when parent helper changes angle. (Read 1030 times)

Started by Dwagoniss, November 09, 2017, 01:15:08 pm
Share this topic:
Changing child helper velocity when parent helper changes angle.
#1  November 09, 2017, 01:15:08 pm
  • avatar
Apologies but I've run out of ideas for this, and after consulting multiple topics I still can't figure it out.

My goal is for the root to spawn in the middle of the screen and to create a helper as a blaster/gun which can be rotated by the player using left or right buttons. Pressing another button will allow you to shoot a child helper/bullet but I can't figure out how to make the velocity change in accordance with the angle of the blaster. I tried saving the angle as a variable but I have no idea what to do with it.

I'm utterly hopeless at mathematics/physics and even programming in general so its got me completely stumped.
Here's the code for the blaster helper and the bullet helper.

Code:
;-------------------------------------------------------------------------
;blaster idle state
[statedef 773]
type = a
movetype = u
physics = n
anim = 777
sprpriority=5

[State 0, BindToRoot]
type = BindToParent
trigger1=!time
trigger2=time=640 ;safety
time = 1
pos = 35,-75

[State 0, Angle]
type = AngleDraw
trigger1=1

[State 0, ParentVarSet]
type = ParentVarSet
trigger1=!time
fv = 0
value = 3

[State 0, AngleDraw]
type = Angleadd
trigger1=root, command = "holdfwd"
value=3

[State 0, AngleDraw]
type = Angleadd
trigger1=root, command = "holdback"
value=-3

[State 0, ParentVarSet]
type = ParentVaradd
trigger1=root, command = "holdfwd"
fv = 0
value = 3

[State 0, ParentVarSet]
type = ParentVaradd
trigger1=root, command = "holdback"
fv = 0
value = -3

[State 0, ParentVarSet]
type = ParentVarSet
trigger1=parent,fvar(0) >= 360
trigger2=parent,fvar(0) <= -360
fv = 0
value = 0

[State 0, PlaySnd]
type = PlaySnd
trigger1 = root, command = "c"
value = S770,0

;shooting
[State 0, ChangeState]
type = changeanim
trigger1 = root, command = "c"
value=778

[State 0, Helper]
type = Helper
trigger1 = root, command = "c"
helpertype = normal ;player
name="pea"
ID=775
stateno=775
pos = 0,5
postype = p1    ;p2,front,back,left,right
facing = 1
keyctrl = 0
ownpal = 0

[State 0, DestroySelf]
type = DestroySelf
trigger1=time>500
trigger2=root,stateno=0
ignorehitpause = 1
;-------------------------------------------------------------------------
;ammo
[statedef 775]
type = a
movetype = a
physics = n
anim = 780
sprpriority=5

[state 701]
type=hitdef
trigger1=!time
attr=S,NA
getpower=0,0
damage=6+random%3,1
priority=3,Hit
hitflag=MAF
guardflag=MA
pausetime=2,9
hitsound=S700,0
guardsound=S105,0
sparkno=9999
sparkxy=9999,9999
ground.velocity=-2,0
ground.type=low
ground.hittime=10
air.velocity=-1,-1
air.hittime=12

[State 0, AssertSpecial]
type = AssertSpecial
trigger1=1
flag = noshadow

[State 0, BindToRoot]
type = BindToparent
trigger1=!time
time = 1
pos = 0,0

[State 0, ChangeState]
type = Destroyself
trigger1=pos y >= 0
trigger2=movecontact
trigger3=time>100

EDIT: Added a picture to perhaps help with context.



Any advice/help would be greatly appreciated.
Last Edit: November 09, 2017, 02:01:24 pm by Dwagoniss
Re: Changing child helper velocity when parent helper changes angle.
#2  November 09, 2017, 03:47:26 pm
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
I don't have the full solution, but a few good tips until hopefully someone with better math skills can help :)

You can just use one of the Helper's Vars - it doesn't look like you would need to relay it to the parent.

For starters, I would instead just use VarSet to keep track of the angle, and use the Var for the angle value of the AngleDraw

Code:
[State 0, VarSet]
type = VarSet
trigger1=!time
fvar(0) = 3

[State 0, Angle]
type = AngleDraw
trigger1=1
value = fvar(0)

[State 0, AdjustAngle]
type = VarAdd
trigger1=root, command = "holdback"
value=-3

[State 0, AdjustAngle]
type = VarAdd
trigger1=root, command = "holdfwd"
value=3

The pea helper then uses it's parent's Var to set the velocity.  Don't bind it to the parent or it won't move anywhere :)

So these x/y values are absolutely wrong, but the concept will be something like:

Code:
[State 0, AttackDirection]
type = VelSet
trigger1=!time
x = 0 + parent,fvar(0)
y = 10 + parent,fvar(0)